Unknown reference to __dlopen in dlopen

删除回忆录丶 提交于 2019-12-03 15:32:05

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

$ 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/

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.

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

gcc <file> -static -ldl -lc

should fix the problem in your system.

You should be able to use the shared library libdl.so with

gcc -ldl ...

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!