简体   繁体   English

将共享库与静态库链接

[英]Linking shared library against static library

I have two autotools-based projects AAA and BBB: 我有两个基于autotools的项目AAA和BBB:

  • AAA is built with "--enable-static --disable-shared", all code written in C AAA使用“--enable-static --disable-shared”构建,所有代码都用C语言编写
  • BBB is a dynamic library, and links against AAA using "libBBB_la_LIBADD = /path/to/libAAA.a" BBB是一个动态库,使用“libBBB_la_LIBADD = /path/to/libAAA.a”链接AAA

I'm getting the following when trying to compile BBB: 在尝试编译BBB时,我得到以下内容:

/usr/bin/ld: /usr/local/lib/libAAA.a(liboAAA_la-foo.o): relocation R_X86_64_PC32 against undefined symbol `malloc@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

For reference, the actual command that's generating the error is: 作为参考,产生错误的实际命令是:

gcc -shared  -fPIC -DPIC  .libs/libBBB_la-BBB.o .libs/libBBB_la-hash.o .libs/libBBB_la-vl_helpers.o   -lm -L/usr/local/lib /usr/local/lib/libAAA.a  -O3   -Wl,-soname -Wl,libBBB.so.0 -o .libs/libBBB.so.0.0.0

What am I doing wrong, and how do I make this work? 我做错了什么,我该如何做到这一点?

libAAA should be built with -fPIC to get position-independent code. 应使用-fPIC构建libAAA以获取与位置无关的代码。 In the current setup, you're trying to build a mixed PIC/non-PIC libBBB , which is not allowed. 在当前设置中,您尝试构建混合PIC /非PIC libBBB ,这是不允许的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM