开发者

Unknown reference to __dlopen in dlopen

dlopen is located in libdl.a but when I link my applicatio开发者_开发知识库n against libdl.a , gcc linker throw this error : unknow reference to __dlopen called in dlopen

Should I import another .a?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜