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

查看:96
本文介绍了对“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?

推荐答案

好吧,我找到了答案,我需要 -Wl,--no-as-needed 标志在 - 之前ldl.在我问这个问题之前,我遇到过这个标志,但显然打错了它,因为它对我不起作用.

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 用户 here 说这与最近的 (2013 年用户的帖子)链接到 --as-needed 的 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天全站免登陆