Linux dlopen 中对 __dlopen 的未知引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7526255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:19:40  来源:igfitidea点击:

Unknown reference to __dlopen in dlopen

c++linuxshared-libraries

提问by Guillaume07

dlopenis located in libdl.abut when I link my application against libdl.a, gcc linker throw this error : unknow reference to __dlopen called in dlopen

dlopen位于libdl.a但是当我将我的应用程序链接到时libdl.a,gcc 链接器会抛出此错误:unknow reference to __dlopen called in dlopen

Should I import another .a?

我应该导入另一个.a吗?

采纳答案by Kevin

When I try to compile statically a dlopenmockup program, gcc(Archlinux/gcc version 4.6.1 20110819 (prerelease)) tells me:

当我尝试静态编译一个dlopen模型程序时,gcc(Archlinux/gcc version 4.6.1 20110819 (prerelease)) 告诉我:

$ gcc test.c  -ldl -static  
/tmp/ccsWe4RN.o: In function `main': test.c:(.text+0x13): 
warning: Using 'dlopen' in statically linked applications requires 
at runtime the shared libraries from the glibc version used for linking

and indeed, when I ran this script in /usr/lib/

事实上,当我运行这个脚本时 /usr/lib/

for i in *.a; 
do 
    echo $i; 
    readelf -a $i | grep __dlopen;
done

I saw:

我看见:

libc.a
16: 0000000000000080    69 FUNC    GLOBAL DEFAULT    1 __dlopen
000000000000  002300000001 R_X86_64_64       0000000000000000 __dlopen + 0
35: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND __dlopen

so as per the first line, libc.adoes define your missing symbole.

所以根据第一行,libc.a确实定义了您缺少的符号。

In my system, gcc test.c -ldl -staticis enough to make the application run, but

在我的系统中,gcc test.c -ldl -static足以使应用程序运行,但是

gcc <file> -static -ldl -lc

should fix the problem in your system.

应该解决您系统中的问题。

回答by Kevin

You should be able to use the shared library libdl.sowith

您应该能够使用共享库libdl.so

gcc -ldl ...

if you don't have a strong requirement on using the static version.

如果您对使用静态版本没有强烈要求。