未定义的'dlsym'参考

时间:2013-12-04 07:38:18

标签: c++ gcc compiler-errors ubuntu-13.10

我看过很多类似的帖子,但是在书中尝试了每一个技巧,我仍在苦苦挣扎。一切都工作正常,但在安装/删除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一起使用。

1 个答案:

答案 0 :(得分:39)

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

  

gcc main.cpp -lsqlapi -lstdc ++ -Wl, - no-as-needed -ldl

显然它与最近版本的gcc / ld默认与--as-needed链接有关。