[英]Undefined reference to 'dlsym' and 'dlopen'
I am compiling using arm-linux-gnueabi-g++ version 4.7.3. 我正在使用arm-linux-gnueabi-g ++ 4.7.3版进行编译。
I have the arm-linux-gnueabi libraries installed at location: 我在位置安装了arm-linux-gnueabi库:
/usr/arm-linux-gnueabi/lib, it contains libdl.a, libdl.so, libdl.so.2, and libdl-2.19.so. / usr / arm-linux-gnueabi / lib,它包含libdl.a,libdl.so,libdl.so.2和libdl-2.19.so。
libdl.so links to libdl.so.2 which links to libdl-2.19.so. libdl.so链接到libdl.so.2,链接到libdl-2.19.so。
I am trying to link against the dl library (see command string below), but I always get the undefined reference errors. 我试图链接到dl库(请参阅下面的命令字符串),但我总是得到未定义的引用错误。
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
If I compile using g++ 4.8.2 using the following commend then my program compiles, links, and executes fine. 如果我使用g ++ 4.8.2使用以下命令编译,那么我的程序编译,链接和执行正常。
g++ -I. -I../ -I../Comms/Linux -Wall -DLINUX -fpic -o ../../work/MyProgram main.o
-L../../work -lComms -lConsole -lUtilities -ldl
Obviously it can't find the libdl.so library; 显然它找不到libdl.so库; 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. 我认为通过使用-L
标志将路径添加到相应库的位置可以解决问题,但事实并非如此。
What am I missing with the ARM compiler command? 我对ARM编译器命令缺少什么?
Well, I found the answer, I needed -Wl,--no-as-needed
flag before the -ldl
. 好吧,我找到了答案,我需要-Wl,--no-as-needed
在-ldl
之前-Wl,--no-as-needed
标记。 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. 我不明白为什么需要这个标志,但代码现在完成链接。
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. 这里的SO用户说它与最近(2013年用户的帖子)版本的gcc链接到--as-needed有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.