libpython2.7.a missing many references

2019-07-26 08:13发布

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.

1条回答
仙女界的扛把子
2楼-- · 2019-07-26 08:38

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

查看更多
登录 后发表回答