I am new to Cython and I am trying to convert a python file to a C file and then to an executable using Cython, but after generating the C file when I try to compile it using GCC in Windows I get a lot of Undefined reference errors:
Here's what I did;
My pyx file:
cdef public void fun():
print('hello, world!')
if __name__ == "__main__":
fun()
Then I used this code to generate the C file:
python -m cython hello.pyx --embed -3
this went succesfully and I got a hello.c file. Then I tried to compile this using:
x86_64-w64-mingw32-gcc -mconsole -DSIZEOF_VOID_P=8 hello.c -IE:\phyton\include -LE:\phyton\libs -lpython38 -o hello.exe -DMS_WIN64
but that didn't work and I got this:
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
So where is my mistake, most of the time this has to do with linking libraries, but I have done that properly so can anybody help?