cython: Symbol Undefined...
I have read multiple examples for generating an so library using cython’s pure python interface, and then later calling a function in it. THE FUNCTION IS NOT GETTING DEFINED IN THE SO!
- The pure python code:
#cython: language_level=3
import cython
@cython.cfunc
@cython.returns(cython.int)
@cython.locals(a=cython.int)
def blah(a):
return 42
- The cython command:
cython3 test.py - The gcc step:
gcc -fpic `python3-config --cflags` -o test.o -c test.c - generate an so from the compilation output:
gcc -shared -o test.so test.o `python3-config --libs` - List the entrypoints in the so:
nm -D test.so|less
# (I'm not seeing the function "blah" there!)
- Try accessing the so:
python3
from ctypes import CDLL
so=CDLL('./test.so')
dir(so)
['_FuncPtr', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_func_flags_', '_func_restype_', '_handle', '_name']
# NO "blah" function!
All the pure python examples take it as a given that it will show up.
cython version: 0.29.30 python version: 3.9.2 gcc version: 10.2.1 ctypes version: 1.1.0 OS: Debian 11
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (9 by maintainers)
So to generate an so, I guess I want to do the setup.py with the cythonize call.
They are doing it with a pyx for input; can I pass a pure-python py file?
[I found 2 online examples doing it the gcc way I listed above; I figured once you have the c file generated by cython, the function call representing the call to the python function should be exposed thanks to those decorators I used above and found online…]
python setup.py build_ext --inplace test.pyAnd: thanks so far…