I’m learning cython and the exercise I’m doing wants me to make a lib (.so) to use in a C program (already compiled), that require that lib. I already have done the lib. It is working.
But now, I need to make the .so file. I’m struggling very hard with that to make the functions visible to the program. I have found many posts of doing the opposite (C->Python), but that is not what I want.
My pipeline is:
cython --embed csv_reader_lib/process_csv_file.py -o libcsv.c
gcc -o libcsv.so -shared -fPIC libcsv.c $(python3-config --cflags --ldflags) -lpthread -lm -lutil -ldl -lpython3.12
cp libcsv.so /usr/local/lib/
./my_exec
This kind of “works”. The lib is generated, but my program cannot find the functions I export.
The error I receive is this:
/app # ./test_libcsv
Error relocating ./test_libcsv: processCsvFile: symbol not found
Error relocating ./test_libcsv: processCsv: symbol not found
My main python file is something like:
import cython
@cython.cfunc
def processCsvFile(csv: cython.p_char, selectedColumns:cython.p_char, rowFilterDefinitions:cython.p_char):
...
@cython.cfunc
def processCsv(csv_data:cython.p_char, selectedColumns:cython.p_char, rowFilterDefinitions:cython.p_char):
...
I’m missing something? Would appreciate any help. Thank you very much.
After @AndrewHenle comment, Running nm libcsv.so
shows a lot of py functions and some of my functions, but not the functions I made on main.pyx:
nm libcsv.so | grep -I csv
00000000000024ee T PyInit_process_csv_file
00000000000052d8 r __pyx_k_csv_filter
00000000000052a8 r __pyx_k_csv_reader_lib
00000000000052c8 r __pyx_k_csv_to_dict
00000000000052e8 r __pyx_k_print_csv
00000000000052f8 r __pyx_k_read_csv
0000000000007140 B __pyx_module_is_main_csv_reader_lib__process_csv_file
0000000000002fdc t __pyx_pymod_exec_process_csv_file
Why are my exported functions still with _ in name and the exported does not appear?
Thank you.
jessica arruda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5