Compiling and using Cython C file independently

549 views
Skip to first unread message

Shuangyi Li

unread,
Dec 9, 2021, 3:23:02 AM12/9/21
to cython-users
Dear cythoners,

I am wondering how to compile and use cython .c file indepently, not in python.

as far as I know, in general, people use cython to get .pyd file and import them in other .py file to get speed improved. But now I want use the output .C file independently, not in a python enviroment.

So far, I have tried to directly use GCC to compile .C files obtained through cython. 
The command is:

gcc hello.c -L C:......\Python\Python310\libs\python310.lib -fPIC -DMS_WIN64

The error prompt is:

undefined reference to `__imp_PyType_IsSubtype'
undefined reference to `__imp__Py_Dealloc'
undefined reference to `__imp_PyModuleDef_Init'
and so many similar errors.

I think this is a problem with the .lib file, but I don't know whether I connected the .lib file in the wrong way or I connected the wrong lib file. Does anyone have any suggestions? What should I do?

Thanks to all

Robert Bradshaw

unread,
Dec 9, 2021, 3:42:45 AM12/9/21
to cython...@googlegroups.com
The generated .c file depends on the Python C API, and needs to be
linked against the Python libraries to work.

You can, however, implement utilities in Cython and invoke them from
other .c files. See
https://cython.readthedocs.io/en/latest/src/tutorial/embedding.html
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/6c299a7b-930f-4337-8000-25f2d18286fcn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages