我看过很多类似的文章,但是尝试了本书中的所有技巧,但仍然很挣扎。一切工作正常,但是在安装/卸下带有某些组件/取消选择器的wireshark之​​后,一切都搞砸了。我不记得确切地卸载了哪些库/软件包,但是可能比我注意到的要多得多。

如果我像这样创建一个简单的main.cpp文件:

#include <SQLAPI.h>
int main()
{
  SAConnection con;
  return 0;
}

并尝试



它给了我以下错误信息:
/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。

在g++版本4.8.1中使用Ubuntu 64位13.10。

最佳答案

我找到了解决方案;设置-Wl,在-ldl之前不需要-新的编译命令是



显然,这与gcc/ld的最新版本default有关,即按需链接。

关于c++ - 未定义对 'dlsym'的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20369672/

10-10 18:06