链接共享库时,Ubuntu链接器不解析符号

时间:2015-01-23 20:06:15

标签: ubuntu gcc linker

我正在玩libturbojpeg的一些基本Python绑定我想在我的项目中使用。一切都在Debian(sid)中完美运行,但是当使用Ubuntu(可靠)构建项目时,链接器显然无法正确解析符号。

代码库位于https://github.com/subotto/streamingmake _pytj.so应该做的伎俩,它适用于Debian(它使用SWIG生成C代码,用我的其他自定义代码编译它然后链接它)。生成的库_pytj.so具有所有正确的依赖关系。

而在Ubuntu上,生成的库错过了依赖项:

$ ldd _pytj.so
linux-vdso.so.1 =>  (0x00007fff968e2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f12229d8000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1222fe0000)

(它应该依赖于turbojpeg和Python库)。

当然,如果我尝试导入生成的模块,python解释器会抱怨未解析的符号。

如果我将-Wl,-z,defs添加到链接编译行:

$ gcc -shared -o _pytj.so `python-config --libs` -lturbojpeg _pytj.o  _pytj_wrap.o -Wl,-z,defs 2>&1 | head
_pytj.o: In function `create_tjcontext':
_pytj.c:(.text+0x17): undefined reference to `tjInitCompress'
_pytj.c:(.text+0x23): undefined reference to `tjInitDecompress'
_pytj.o: In function `free_tjcontext':
_pytj.c:(.text+0x4c): undefined reference to `tjDestroy'
_pytj.c:(.text+0x5c): undefined reference to `tjDestroy'
_pytj.o: In function `encode_image':
_pytj.c:(.text+0xf7): undefined reference to `tjCompress2'
_pytj.o: In function `free_encoded_image':
_pytj.c:(.text+0x128): undefined reference to `tjFree'

显然,链接器理解我的链接到指定库的请求。正如我所说,Debian sid中的命令行完全正常。

我错过了什么?

编辑如果我按照评论中的建议使用另一个命令行,则会出现另一个错误:

$ gcc -shared -o _pytj.so _pytj.o _pytj_wrap.o `python-config --libs` -lturbojpeg -Wl,-z,defs 2>&1 | head
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libturbojpeg.a(libturbojpeg_la-turbojpeg.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libturbojpeg.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

但是我的理解是,必须在使用它们的对象之前指示具有-l的库。

0 个答案:

没有答案