I'm trying to compile a cython
module with -static
, but I am getting a lot of errors about missing references in libpython2.7.a
. For example:
/usr/lib/x86_64-linux-gnu/libpython2.7.a(complexobject.o): In function `_Py_c_pow':
(.text.unlikely+0x507): undefined reference to `pow'
I already have the package build-essential
installed, which is one solution I found on Google.
My work flow is:
cython --embed hi.py
gcc hi.c -lpython2.7 -I /usr/include/python2.7 -static
What am I missing to be able to link this file statically?
EDIT: Added additional linker options
gcc hi.c -lpython2.7 -lm -pthread -lzlib -I /usr/include/python2.7 -static
All the references to undefined functions went away, but ld is saying it can't find lzlib so compilation still fails. Without -lzlib
I still get some undefined references.
As your package manager will show you, the library for zlib is
libz.so
, hence you must pass-lz
.Added by question owner: For other's reference all the linker options needed
-lpython2.7 -lm -ldl -lutil -lz -pthread