对“dlsym"的未定义引用

Undefined reference to #39;dlsym#39;(对“dlsym的未定义引用)

本文介绍了对“dlsym"的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多类似的帖子,但尝试了书中的所有技巧,仍然在挣扎.一切正常,但是在安装/删除带有一些组件/选择器的wireshark之​​后,一切都搞砸了.我不记得到底卸载了哪些库/包,但可能比我注意到的要多得多.

I have seen a lot of similar posts, but tried every trick in the book and am still struggling. Everything was working fine, but after installing/removing wireshark with some components/disselectors it all got messed up. I don't remember exactly which libraries/packages got uninstalled, but probably a lot more than I noticed.

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

If I create a simple main.cpp file like this one:

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

然后尝试

g++ main.cpp -lsqlapi -ldl

g++ main.cpp -lsqlapi -ldl

它给了我以下错误消息:

it gives me the following error messages:

/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++,则错误是:

I have tried to put -ldl before -lsqlapi as some have suggested that the order is important. If I use gcc instead of g++ the error is:

/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,我可以编译和运行该文件.

I am able to compile and run the file if SAConnection is removed.

我不认为它与 SQLAPI 有任何关系,因为我在使用 libboost 时遇到了类似的问题.我没有小代码示例,但是当我编译上周成功编译的项目时,出现错误:

I don't think it has anything to do with SQLAPI, because I experience similar problems with libboost. I don't have a small code example, but when I compile a project that was successfully compiled last week, I get the error:

/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.

This project is using a Makefile that has been unchanged, so it has to be something on my system that is not correct. I have tried to reinstall build-essential.

使用 Ubuntu 64 位 13.10 和 g++ 版本 4.8.1.

Using Ubuntu 64 bit 13.10 with g++ version 4.8.1.

推荐答案

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

I have found the solution; setting the -Wl,--no-as-needed before -ldl The new compile command is

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

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

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

Apparently it has something to do with recent versions of gcc/ld default to linking with --as-needed.

这篇关于对“dlsym"的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:对“dlsym"的未定义引用