C 将共享库与静态库链接

C 将共享库与静态库链接,c,linker,ld,autotools,libtool,C,Linker,Ld,Autotools,Libtool,我有两个基于自动工具的项目AAA和BBB: AAA是用“-enable static--disable shared”构建的,所有代码都是用C编写的 BBB是一个动态库,使用“libBBB_la_LIBADD=/path/to/libAAA.a”链接AAA 在尝试编译BBB时,我得到以下信息: /usr/bin/ld: /usr/local/lib/libAAA.a(liboAAA_la-foo.o): relocation R_X86_64_PC32 against undefined s

我有两个基于自动工具的项目AAA和BBB:

  • AAA是用“-enable static--disable shared”构建的,所有代码都是用C编写的
  • BBB是一个动态库,使用“libBBB_la_LIBADD=/path/to/libAAA.a”链接AAA
在尝试编译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
作为参考,生成错误的实际命令是:

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

我做错了什么,我该怎么做?

libAAA
应该使用
-fPIC
构建,以获得位置独立的代码。在当前设置中,您试图构建混合PIC/非PIC
libBBB
,这是不允许的