1

I converted a Python script to C code via Cython, creating "test.c". I then compile with:

 gcc -static test.c -I/home/me/Python-3.9.12/include/python3.9 -o test.exe  -L/home/me/Python-3.9.12/lib -lpython3.9 -lpthread -lutil -lrt -lm -ldl

When I run "test.exe" I get this error:

 Original error was: /home/me/NEWER/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-gnu.so: undefined symbol: PyObject_SelfIter

What I don't understand is that the symbol PyObject_SelfIter is defined in libpython3.9.a which I link in as seen in the compilation line. Why doesn't this linking take care of the undefined symbol noted above? How can I get around this error?

2 notes:

  1. I am linking statically because I want to run the resulting executable on an Android system
  2. as a test, I tried compiling without the -static flag, and the executable still yields the same error

thanks for any tips.

user3063547
  • 739
  • 1
  • 8
  • 18
  • 1
    You need `-Xlinker -export-dynamic` when building: similar (but somehow different question) https://stackoverflow.com/a/67894308/5769463 with more explanation about this flag. – ead Sep 08 '22 at 10:25
  • Thanks ead for that. When I add -Xlinker -export-dynamic and drop -static, it compiles fine and runs fine. Apparently, compiling with -static is not a good idea when gibc is being linked in. I found this online where someone wrote: "reading the LGPL makes it very clear that applications statically linking glibc must be open-source". Since I wouldn't want to supply all the source I will steer clear of static linking. When I do "ldd test.exe" part of it shows: libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 which is glibc. Now I have to figure out how to run this executable on Android.,,. – user3063547 Sep 08 '22 at 20:33

0 Answers0