C++ libpthread和libc中未定义的引用

C++ libpthread和libc中未定义的引用,c++,linux,linker,g++,undefined-reference,C++,Linux,Linker,G++,Undefined Reference,在odbc sdk中编译一些示例时遇到问题。经过一段时间与图书馆的顺序混在一起后,我不知何故设法只获得了其中一小部分未定义引用的数量 可悲的是,我不知道如何摆脱剩下的。以下是失败的命令: g++ -Wall -z defs -m64 -DSIMBA -D_REENTRANT -fPIC -O0 -g -shared Common/TabbedUnicodeFileReader_Linux_x8664_debug.cpp.o Core/QSConnection_Linux_x8664_debug.

在odbc sdk中编译一些示例时遇到问题。经过一段时间与图书馆的顺序混在一起后,我不知何故设法只获得了其中一小部分未定义引用的数量

可悲的是,我不知道如何摆脱剩下的。以下是失败的命令:

g++ -Wall -z defs -m64 -DSIMBA -D_REENTRANT -fPIC -O0 -g -shared Common/TabbedUnicodeFileReader_Linux_x8664_debug.cpp.o Core/QSConnection_Linux_x8664_debug.cpp.o Core/QSDriver_Linux_x8664_debug.cpp.o Core/QSEnvironment_Linux_x8664_debug.cpp.o Core/QSStatement_Linux_x8664_debug.cpp.o DataEngine/QSDataEngine_Linux_x8664_debug.cpp.o DataEngine/QSMetadataHelper_Linux_x8664_debug.cpp.o DataEngine/QSTable_Linux_x8664_debug.cpp.o DataEngine/QSTableUtilities_Linux_x8664_debug.cpp.o DataEngine/QSTypeInfoMetadataSource_Linux_x8664_debug.cpp.o Common/QSTableMetadataFile_Unix_Linux_x8664_debug.cpp.o Common/QSUtilities_Unix_Linux_x8664_debug.cpp.o Main_Unix_Linux_x8664_debug.cpp.o    -Wl,--no-undefined -Wl,--no-allow-shlib-undefined -Wl,--whole-archive,/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//Lib/Linux_x8664/libSimbaDSI_debug.a,/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//Lib/Linux_x8664/libSimbaSupport_debug.a,/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//Lib/Linux_x8664/libAEProcessor_debug.a,/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//Lib/Linux_x8664/libCore_debug.a,/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//Lib/Linux_x8664/libDSIExt_debug.a,/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//Lib/Linux_x8664/libExecutor_debug.a,/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//Lib/Linux_x8664/libParser_debug.a,/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//Lib/Linux_x8664/libSimbaODBC_debug.a -Wl,--no-whole-archive -Wl,--soname=../Bin/Linux_x8664/libQuickstart_debug.so -L/home/hector/Downloads/SimbaEngineSDK/9.0/DataAccessComponents//ThirdParty/icu/Linux_x8664/lib -licuuc_simba64 -licudata_simba64 -licui18n_simba64 -lpthread -lm -lc -ldl -Wl,--version-script=exports_Linux.map -o ../Bin/Linux_x8664/libQuickstart_debug.so
编辑:缺少符号

/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libdl.so: undefined reference to `_dl_rtld_di_serinfo@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `_dl_allocate_tls_init@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `__libc_stack_end@GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `_dl_get_tls_static_info@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `__tls_get_addr@GLIBC_2.3'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `_dl_deallocate_tls@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `_rtld_global@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_argv@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `_dl_allocate_tls@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `_dl_make_stack_executable@GLIBC_PRIVATE'
固定的:


删除-Wl,--no-allow-shlib undefined似乎起到了作用。构建的共享库似乎工作得很好。

您犯了一个非常常见的新手错误。将库放置在命令行的中间或开始处链接。链接器GCC按相反顺序使用需求依赖项。这意味着,如果源/对象文件S使用库L中的函数,则命令行上的文件a必须位于库L之前


简而言之,将库(
-lm-lc-ldl
)放在命令行的最后一位。

如果链接器无法解析所有引用的符号,则这可能是由于提供的库顺序错误造成的。如果您不确定什么是正确的顺序,那么将归档放入“-start group archives--end group”,根据ld手册,它将强制链接器重复搜索指定的归档,直到没有创建新的未定义引用为止。但是要注意性能成本。

我在一个完全独立的应用程序中遇到了类似的问题。以下编译时标志适用于我:

-B/usr/lib/gold ld/

我在以下网站找到:


我正在使用gcc(Ubuntu/Linaro 4.6.1-9ubuntu3)4.6.1,我试图用lto进行编译。

发布您收到的错误消息。缺少哪些符号?我在帖子里看不到…@HectorIzquierdo你在两个地方都有图书馆。如果链接器已加载库,则不会再次加载,然后查找将失败。删除源/对象文件之前的所有库,并将它们保留在最后。感谢Joachim的提示。遗憾的是,我仍然得到相同的未定义的引用错误