未定义的引用'dlsym' [英] Undefined reference to 'dlsym'

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

问题描述

我看到很多类似的帖子,但试图在书中的每一个伎俩,仍然在努力。一切都工作正常,但安装/删除wireshark与一些组件/ disselectors后,一切都搞乱了。我不记得哪些库/包被卸载,但可能比我注意到的更多。



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

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

并尝试



< >

g ++ main.cpp -lsqlapi -ldl


它会显示以下错误讯息:

  /usr/local/lib/libsqlapi.so:未定义引用`dlsym'
/ usr / local / lib / libsqlapi .so:未定义的引用`dlerror'
/usr/local/lib/libsqlapi.so:未定义对`dlopen'的引用
/usr/local/lib/libsqlapi.so:undefined对`dlclose '
collect2:error:ld returned 1 exit status

之前的-lsqlapi为一些已经建议的顺序很重要。如果我使用gcc而不是g ++的错误是:

  / usr / bin / ld:/tmp/ccwBI4tj.o:undefined引用符号'__gxx_personality_v0 @@ CXXABI_1.3'
/usr/lib/x86_64-linux-gnu/libstdc++.so.6:添加符号时出错:命令行中缺少DSO
collect2:error:ld返回1退出状态



如果删除SAConnection,我可以编译并运行该文件。 >

我认为它与SQLAPI没有任何关系,因为我遇到类似的问题libboost。我没有一个小代码示例,但是当我编译上周成功编译的项目,我得到的错误:

  / usr / bin / ld:debug / components / helloworld / HelloWorld.o:未定义引用符号'_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0:error添加符号:命令行中缺少DSO
collect2:错误:ld返回1退出状态

这个项目使用一个没有改变的Makefile,所以它必须在我的系统上是不正确的。我已尝试重新安装build-essential。



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

解决方案

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


gcc main.cpp -lsqlapi -lstdc ++ -Wl, - 不需要-ldl


显然,它与最近的gcc / ld版本有关链接 - 需要。


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.

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

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

and try

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

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

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

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

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.

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

解决方案

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

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

这篇关于未定义的引用'dlsym'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆