2016-03-15 86 views
6

我试图在汇编语言功能,并把它们放在一个动态库,所以我创建的.o与此命令.S:
nasm -f elf64 hello.S -o hello.o
但是当我要创建用gcc LIB:
gcc -fPIC -shared hello.o -o libasm.so
并显示我这个错误:
/usr/bin/ld: hello.o: relocation R_X86_64_PC32 against undefined symbol [email protected]@GLIBC_2.2.5 can not be used when making a shared object; recompile with -fPIC编译错误:对未定义的符号搬迁R_X86_64_PC32

+2

请参阅http://www.nasm.us/xdoc/2.10rc8/html/nasmdoc9.html#section-9.2.5(_库外的调用过程) – Michael

回答

4

http://www.nasm.us/xdoc/2.10rc8/html/nasmdoc9.html#section-9.2.5

To call an external routine, you must use another special PIC relocation type, WRT ..plt. This is much easier than the GOT-based ones: you simply replace calls such as CALL printf with the PLT-relative version CALL printf WRT ..plt.

所以不是

; ... 
call  printf 

使用

; ... 
call  printf WRT ..plt 

,并编译和链接正常。

相关问题