静态库中未定义的符号链接到动态库

Undefined symbol in static lib linked into dynamic library

本文关键字:动态 符号链接 未定义 静态      更新时间:2023-10-16

这是我的问题:

在运行时,我的程序加载共享库无法加载一个,它说:

libCommunicationModule.so: undefined symbol __builtin_delete

背景:

  • 编译器:GCC 3.4
  • Linux Debian 4.0 (老东西...

我有一个静态库:libtgi_cppd.a,我没有这个库的来源。此库链接到具有这些选项 libCommunicationModule.so 共享库 -Wl,-whole-archive -ltgi_cppd

我在__builtin_delete上启用了-y选项以检查:

libtgi_cppd.a(ClientAPI_cpp.o): reference to __builtin_delete
libtgi_cppd.a(ClientInterface.o): reference to __builtin_delete
libtgi_cppd.a(ClientAPI_cpp.o): reference to __builtin_delete

我尝试在-whole-archive之前和之后添加链接命令-lstdc++ -lgcc,没有变化。

$ nm libCommunicationModule.so | grep __builtin

结果总是这样的:

     U __builtin_delete
     U __builtin_new
     U __builtin_vec_new

我该怎么做才能解决这个问题?

谢谢

所需的完整命令:

g++ -Wl,-y -Wl,__builtin_delete -Wl,--trace -Wl,-rpath,/usr/local/qt/lib -shared 
-Wl,-soname,libCommunicationModule-x11-Debug.so.6 -Wl,-rpath,/home/sncf/AGC_IHM/AGC/Tms/Gui/Components/CommunicationModule/x11/Debug 
-o libCommunicationModule-x11-Debug.so.6.0.1 x11/Debug/Obj/CommunicationModule-Build.o x11/Debug/Obj/CommunicationModuleFilesAutoGen.o x11/Debug/Obj/CommunicationModuleParamsAutoGen.o 
x11/Debug/Obj/CommunicationModule.o 
x11/Debug/Obj/CommunicationModuleAutoGen.o 
x11/Debug/Obj/CommDebugDlg.o 
x11/Debug/Obj/moc_CommunicationModule.o x11/Debug/Obj/moc_CommDebugDlg.o  
-L/usr/local/qt/lib 
-L/usr/X11R6/lib -lBuildInformations-x11-Debug 
-lBagsLib-x11-Debug -lConfigParamsLib-x11-Debug 
-lIniLib-x11-Debug -lModuleHandling-x11-Debug 
-lGenericRuntimeInfoLib-x11-Debug 
-lDebugLib-x11-Debug -lTCNLib-x11-Debug 
-lGUITools-x11-Debug -lQtEventsLib-x11-Debug 
-lPackUnpack-x11-Debug -L/home/sncf/AGC_IHM/AGC/Tms/Gui/ProjectLib/x11 
-L/home/sncf/AGC_IHM/AGC/Tms/Gui/Components/AGCTCNClientAPI/2004.09.21/posix_linux_i586/lib
-lqt-mt -lXext -lX11 -lm -lpthread -Wl,-whole-archive -ltgi_cppd -lstdc++ -lgcc 

您链接到由另一个编译器/链接器版本编译/链接的库。您需要的是链接到由与您使用的相同编译器/链接器编译和链接的库,或者您必须确保这些库至少是二进制兼容的。

  1. 执行命令ldd,它将列出程序使用的所有共享库。

  2. 检查执行环境中的环境变量 LIBPATH/LD_PATH。并确保所有这些库都存在于该路径中

  3. 确保所有库文件都具有足够的权限