Hi,<br><br>I have a problem with compiling Cython code on Windows. I think this is a bug in distutils which is easy to solve. I have reproduced this on Python 2.6 and Python 3.2 (32 bit).<br><br>The problem occurs with the native msvc compiler. Using gcc works fine. And I prefer using gcc, but sometimes you just need msvc :/<br>
<br>The problem is that the command to link the libraries does not put double quotes around paths that have spaces in them. Unfortunately, the path where many users have Python installed have spaces in it (e.g. c:/program files/python26). Small example: <u>/LIBPATH:C:\Program Files (x86)\python32\libs</u>. Oh, and the include_dirs DO have double quotes around them.<br>
<br>The problem is easily solved (I confirmed this) by changing msvc9compiler.py and msvccompiler.py:<br><br>def library_dir_option(self, dir):  # OLD VERSION
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">            return &quot;/LIBPATH:&quot; + dir</p><br>def library_dir_option(self, dir): # FIXED VERSION
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    if &#39; &#39; in dir and not dir.startswith(&#39;&quot;&#39;):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        dir = &#39;&quot;%s&quot;&#39; % dir</p>
<p style="margin:0px;text-indent:0px">    return &quot;/LIBPATH:&quot; + dir</p><br><br>===== Below follows a minimal example =====<br><br>===== test_.pyx<br>def foo():
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    print(&#39;hello&#39;)</p>
<p style="margin:0px;text-indent:0px"><br></p><p style="margin:0px;text-indent:0px">===== setup.py</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">import os, sys</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">from Cython.Distutils import build_ext</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">from distutils.core import setup</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">from distutils.extension import Extension</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">from numpy.distutils.misc_util import get_numpy_include_dirs</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"># Ugly hack so I can run setup.py in my IDE</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">sys.argv = [&#39;setup.py&#39;, &#39;build_ext&#39;, &#39;--inplace&#39;]</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"># Init include dirs</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">include_dirs = [&#39;.&#39;]</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">include_dirs.extend(get_numpy_include_dirs())</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"># Creat Extensions</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">ext_modules = [</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        Extension(&#39;test_&#39;, [&#39;test_.pyx&#39;],</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        include_dirs=include_dirs, </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        ),          </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        ]</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"># Compile</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">setup(</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    cmdclass = {&#39;build_ext&#39;: build_ext},</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    ext_modules = ext_modules,</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    )</p>

<p style="margin:0px;text-indent:0px">print(&#39;Successfully compiled cython file: test_&#39;)</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>===== output when running setup.py<br>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">running build_ext</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">No module named msvccompiler in numpy.distutils; trying from distutils</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">cythoning test_.pyx to test_.c</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">building &#39;test_&#39; extension</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I. -I&quot;C:\Program Files (x86)\python32\lib\site-packages\numpy\core\include&quot; -I&quot;C:\Program Files (x86)\python32\include&quot; -I&quot;C:\Program Files (x86)\python32\PC&quot; /Tctest_.c /Fobuild\temp.win32-3.2\Release\test_.obj</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Found executable C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO <u>/LIBPATH:C:\Program Files (x86)\python32\libs /LIBPATH:C:\Program Files (x86)\python32\PCbuild</u> /EXPORT:PyInit_test_ build\temp.win32-3.2\Release\test_.obj /OUT:C:\almar\projects\py\cmu1394\test_.pyd /IMPLIB:build\temp.win32-3.2\Release\test_.lib /MANIFESTFILE:build\temp.win32-3.2\Release\test_.pyd.manifest</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Found executable C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe</p>
<p style="margin:0px;text-indent:0px">LINK : fatal error LNK1181: cannot open input file &#39;Files.obj&#39;</p><p style="margin:0px;text-indent:0px"><br></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">
<br></p><br>