0

In this question and this reference, there are examples of importing c-header files into Cython, but there is no answer to how can one import a .c file content into Cython.

The .c file which I am interested to import into Cython for my use is: https://github.com/python/cpython/blob/main/Objects/genobject.c

I have two questions:

One

How do I import a .c file into Cython?

Two

Do I need to have the .c file within my directory for it to be accessed? If yes, how do I go about getting https://github.com/python/cpython/blob/main/Objects/genobject.c so that I can use its content in Cython?

I have two .pxd files, cpy.pxd and src.pxd.

In cpy.pxd, I have:

cdef extern from "Python.h":
    cdef int gen_is_coroutine(object o)

In src.pxd, I use it as usual:

if gen_is_coroutine(__value):
    do_something(__value)

I get this Cython compiler error:

constmeta.obj : error LNK2001: unresolved external symbol gen_is_coroutine
build\lib.win-amd64-cpython-310\cy_src\constmeta.cp310-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX86\\x64\\link.exe' failed with exit code 1120
Jim
  • 450
  • 2
  • 10
  • I guess gen_is_corroutin is not marked as public, and thus not visible to the linker (it is definied in python.dll). See e.g. https://stackoverflow.com/a/52216452/5769463, but there are better sources around. – ead Jun 23 '23 at 09:33
  • You can add C code directly in Cython files, which probably means that `#include` directives with a C source will also work: https://docs.cython.org/en/latest/src/userguide/external_C_code.html#verbatim-c – dROOOze Jun 23 '23 at 22:37

0 Answers0