Unable to compile cython generated .c file

2019-08-04 13:27发布

I'm pretty new to python and newer to cython. Since I realized cython is better for me as it is pretty fast, I decided to switch to cython by creating .c files of each .pyx files and I try to compile them manually using the following various techniques:

I create .c file from .pyx using following : I create setup.py file

from distutils.core import setup
from Cython.Build import cythonize

    setup(
        name = "My hello app",
        ext_modules = cythonize("test.pyx"),
    )

It creates a test.c file in same directory. When I try to compile the file using Dev C++, I get following error :

18 C:\crossdev\src\mingw-w64-v3-git\mingw-w64-crt\crt\crt0_c.c undefined reference to `WinMain'

I also tried building .pyx into .c from command prompt using following command :

cython test.pyx

and then doing the following from command prompt to compile using gcc:

python setup.py build_ext --inplace

to create .c file which again fail to compile.

If I try following this link to compile .c file generated by manually including path for Python Includes, I get following error.

I get following error.

PS : I used the gcc -c -IC:\Python27\include -o test.o test.c comand from command line to compile the .c file

PS2 : If I tried manually compiling from cygwin's gcc, it said Fatal Error : No file named Python.h

PS3 : I've manually entered paths for include dirs and libraries in Dev C++ compiler options but the issue persists. The exact error message is as follows :

enter image description here

I tried everything I can find on internet but unable to get any proper solution and I've been facing this issue this since almost a month for which I'm kinda missing deadlines. So It would be very helpful if anyone can guide me in correct path on how to compile .c files generated from Cython.

Thanks in advance

EDIT 1 : I tried the following command to compile my .c file : (In VC++ 2008) E:\My Proj Dir>cl /EHsc test.c /I C:\Python27\include /link C:\Python27\libs\libpython27.a /MACHINE:AMD64

Also tried E:\My Proj Dir>cl /EHsc test.c /I C:\Python27\include /LIBPATH C:\Python27\libs\libpython27.a /MACHINE:AMD64

I get following error : libpython27.a(dmmeh.o) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'

When I tried using /MACHINE:x64, I face the following
test.obj : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

PS : I got AMD64 by importing platform module in my itnterpreter and running platform.machine()

0条回答
登录 后发表回答