对'dlsym'的未定义引用
Undefined reference to 'dlsym'
我看过很多类似的帖子,但我尝试了书中的每一个技巧,仍然在挣扎。一切都很好,但在安装/拆卸了wireshark和一些组件/拆卸器后,一切都一团糟。我不记得具体卸载了哪些库/包,但可能比我注意到的要多得多。
如果我创建一个简单的main.cpp文件,如下所示:
#include <SQLAPI.h>
int main()
{
SAConnection con;
return 0;
}
并尝试
g++main.cpp-lsqlapi-ldl
它会给我以下错误信息:
/usr/local/lib/libsqlapi.so: undefined reference to `dlsym'
/usr/local/lib/libsqlapi.so: undefined reference to `dlerror'
/usr/local/lib/libsqlapi.so: undefined reference to `dlopen'
/usr/local/lib/libsqlapi.so: undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
我试着把-ldl放在-lsqlapi之前,因为有些人认为顺序很重要。如果我使用gcc而不是g++,错误是:
/usr/bin/ld: /tmp/ccwBI4tj.o: undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
如果删除了SAConnection,我就可以编译并运行该文件。
我不认为这与SQLAPI有任何关系,因为我在使用libboost时也遇到过类似的问题。我没有一个小代码示例,但当我编译上周成功编译的项目时,我得到了错误:
/usr/bin/ld: debug/components/helloworld/HelloWorld.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
这个项目使用的是一个未更改的Makefile,所以它在我的系统中一定是不正确的。我已尝试重新安装build essential。
使用Ubuntu 64位13.10与g++版本4.8.1。
我找到了解决方案;将CCD_ 1设置在CCD_。新的编译命令是:
gcc main.cpp -lsqlapi -lstdc++ -Wl,--no-as-needed -ldl
显然,这与最新版本的gcc/ld默认链接--as-needed
有关。
相关文章:
- 编译C++时未定义的引用
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 对 Scalar ::Scalar() 的未定义引用
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 对复制 CTOR 和 CTOR 的未定义引用
- 错误:未定义对'oboe::AudioStreamBuilder::openStream(oboe::AudioStream**)'的引用
- 右值引用未定义的行为
- 对"vtable for DigitalClock"的未定义引用 - 未定义对"DigitalClock::staticMetaObject"的引用 - Qt
- 函数类型到函数类型的引用:未定义的引用
- avcodec_alloc_context引用未定义,但ffmpeg链接顺序正确
- 从c++调用Fortran子程序,链接时引用未定义
- 枚举引用未定义,但位于包含的头文件中