我是Cython的新手,我试图将python文件转换为C文件,然后使用Cython转换为可执行文件,但是生成C文件后,当我尝试在Windows中使用GCC对其进行编译时,我得到了很多未定义的参考错误:
这就是我所做的;
我的pyx文件:
cdef public void fun():
print('hello, world!')
if __name__ == "__main__":
fun()
我的setup.py文件:
import distutils.core
import Cython.Build
distutils.core.setup(ext_modules = Cython.Build.cythonize("hello.pyx"))
然后我使用此代码生成C文件:
python -m cython hello.pyx --embed -3
此操作成功完成,我得到了hello.c文件。然后我尝试使用以下命令进行编译:
x86_64-w64-mingw32-gcc -mconsole -DSIZEOF_VOID_P=8 hello.c -IE:\phyton\include -LE:\phyton\libs -lpython38 -o hello.exe -DMS_WIN64
但是那没有用,我明白了:
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0xf7c): undefined reference to `__imp_PyExc_SystemError'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x1175): undefined reference to `__imp__Py_NoneStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x129c): undefined reference to `__imp_PyUnicode_Type'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x12b7): undefined reference to `__imp_PyUnicode_Type'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x17da): undefined reference to `__imp__Py_NoneStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x17f4): undefined reference to `__imp__Py_NoneStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x19a3): undefined reference to `__imp__Py_FalseStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x19ac): undefined reference to `__imp__Py_TrueStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x19fe): undefined reference to `__imp__Py_FalseStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x1a16): undefined reference to `__imp__Py_FalseStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x1a23): undefined reference to `__imp__Py_TrueStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x21a0): undefined reference to `__imp_PyModule_Type'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x21b8): undefined reference to `__imp_PyModule_Type'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x22b4): undefined reference to `__imp_PyBaseObject_Type'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x284b): undefined reference to `__imp__Py_TrueStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x285f): undefined reference to `__imp__Py_FalseStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x2875): undefined reference to `__imp__Py_NoneStruct'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x28d7): undefined reference to `__imp_PyExc_DeprecationWarning'
C:\Users\STIP\AppData\Local\Temp\ccZz6iu8.o:hello.c:(.text+0x292e): undefined reference to `__imp_PyExc_TypeError'
collect2.exe: error: ld returned 1 exit status
所以我的错误在哪里,大多数时候与链接库有关,但是我做得很好,所以有人可以帮忙吗?