未定义对"dlsym"和"dlopen"的引用 [英] Undefined reference to 'dlsym' and 'dlopen'

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

问题描述

我正在使用arm-linux-gnueabi-g ++版本4.7.3进行编译.

I am compiling using arm-linux-gnueabi-g++ version 4.7.3.

我在以下位置安装了arm-linux-gnueabi库:

I have the arm-linux-gnueabi libraries installed at location:

/usr/arm-linux-gnueabi/lib,其中包含libdl.a,libdl.so,libdl.so.2, 和libdl-2.19.so.

/usr/arm-linux-gnueabi/lib, it contains libdl.a, libdl.so, libdl.so.2, and libdl-2.19.so.

libdl.so链接到libdl.so.2,后者链接到libdl-2.19.so.

libdl.so links to libdl.so.2 which links to libdl-2.19.so.

我正在尝试链接dl库(请参见下面的命令字符串),但是我总是会收到未定义的引用错误.

I am trying to link against the dl library (see command string below), but I always get the undefined reference errors.

arm-linux-gnueabi-g++ -I. -I../ -I../Comms/Linux  -Wall -DLINUX -fpic -o ../../work/MyProgram main.o
-L../../work -L/usr/arm-linux-gnueabi/lib -lComms -lConsole -lUtilities -ldl
../../work/libUtilities.so: undefined reference to `dlsym'
../../work/libUtilities.so: undefined reference to `dlopen'
collect2: error: ld returned 1 exit status

如果使用以下命令使用g ++ 4.8.2进行编译,则我的程序可以进行编译,链接和执行.

If I compile using g++ 4.8.2 using the following commend then my program compiles, links, and executes fine.

g++ -I. -I../ -I../Comms/Linux  -Wall -DLINUX -fpic -o ../../work/MyProgram main.o
-L../../work -lComms -lConsole -lUtilities -ldl

显然,它找不到libdl.so库;我认为通过使用-L标志将路径添加到适当的库的位置可以解决此问题,但是没有解决.

Obviously it can't find the libdl.so library; I thought that by adding the path to the location of the appropriate library by using the -L flag would fix the problem, but it didn't.

ARM编译器命令缺少什么?

What am I missing with the ARM compiler command?

推荐答案

好吧,我找到了答案,在-ldl之前需要-Wl,--no-as-needed标志.在问这个问题之前,我已经碰到过这个标志,但是显然打错了它,因为它对我没有用.

Well, I found the answer, I needed -Wl,--no-as-needed flag before the -ldl. I had run across this flag before I asked the question, but apparently mistyped it because it hadn't worked for me.

我不明白为什么需要标记,但是代码现在确实完成了链接.

I don't understand why the flag is needed, but the code does finish linking now.

SO用户此处说,这与最近的(截止到用户发布的2013年)链接到--as-need的gcc版本.

A SO user here says that it has to do with recent (2013 as of the user's post) versions of gcc linking to --as-needed.

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

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