Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython with Visual Studio (Windoes SDK package) compiler cl.exe to create a .pyd

I am trying to compile a .c file create by Cython to a .pyd file using cl.exe, which comes with the Microsoft Windows SDK.

Since this is the recommended package to build Cython under Windows 7 64 bit for Python 2.7 64 bit, I thought it would be a good idea to use the same compiler to create the .pyd files.

My current call uses a cythoncc.bat file with:

set CLPATH="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\cl.exe"
SET INCLUDE="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include";"C:\Program Files\Microsoft SDKs\Windows\v7.0\Include";"C:\Python27\include";"C:\Python27\Lib\site-packages\numpy\core\include";
SET LIB="C:\Python27\libs";"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib\amd64";"C:\Program Files\Microsoft SDKs\Windows\v7.0\Lib\x64";
SET CFLAGS="/O2 /favor:<INTEL64>"
%CLPATH% %CFLAGS% /Fo%1.pyd %2.c

I think the problem is in the last line, but not sure yet... it gives me the error:

/out:_conecyl.exe
_conecyl.pyd
   Creating library _conecyl.lib and object _conecyl.exp
LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol main referenced
 in function __tmainCRTStartup
_conecyl.exe : fatal error LNK1120: 1 unresolved externals

And creates a .pyd plus a .lib file.

Any help will be very appreciated! Thank you!

like image 811
Saullo G. P. Castro Avatar asked Oct 17 '25 11:10

Saullo G. P. Castro


1 Answers

Use the setup.py recipe explained in the documentation and here


EDIT by Saullo:

the setup.py looked just like this:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("_conecyl", ["_conecyl.pyx"])]

setup(
  name = '_conecyl',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules
)

And with the following calls it worked just perfect:

setenv /x64 / release
set INCLUDE=%INCLUDE%;C:\Python27\include;C:\Python27\Lib\site-packages\numpy\core\include
set LIB=%LIB%;C:\Python27\libs
set DISTUTILS_USE_SDK=1
python setup.py install
like image 128
Viktor Kerkez Avatar answered Oct 20 '25 00:10

Viktor Kerkez