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
Unknown reference to __dlopen in dlopen
提问by Guillaume07
dlopen
is located in libdl.a
but 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 dlopen
mockup 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.a
does define your missing symbole.
所以根据第一行,libc.a
确实定义了您缺少的符号。
In my system, gcc test.c -ldl -static
is 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.so
with
您应该能够使用共享库libdl.so
与
gcc -ldl ...
if you don't have a strong requirement on using the static version.
如果您对使用静态版本没有强烈要求。