我试图在汇编语言功能,并把它们放在一个动态库,所以我创建的.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
6
A
回答
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
,并编译和链接正常。
相关问题
- 1. 编撰错误“未定义的符号”
- 2. 编译错误osx上的“未定义的符号”
- 3. gfortran编译错误:体系结构x86_64的未定义符号
- 4. Centos中未定义的符号错误编译
- 5. 编译器错误:架构x86_64的未定义符号
- 6. 编译器错误E2451未定义的符号在函数main()
- 7. 编译时未定义mpi_win_allocate_shared的符号
- 8. objective c未定义符号编译错误
- 9. 未定义符号错误
- 10. 未定义条件编译符号
- 11. 编译Caffe:未定义符号_H5LTfind_dataset
- 12. 无法编译GLFW,未定义符号
- 13. 编译apache时出错,“未定义符号:未定义符号:”_ apr_dir_read $ INODE64“...... ld:符号未找到”
- 14. g ++未定义的编译错误
- 15. QT未定义的参考信号编译错误
- 16. 编译错误:标签未定义
- 17. C++中的“未定义符号”错误
- 18. 架构错误的未定义符号
- 19. C++中的“未定义符号”错误
- 20. 符号0未定义的错误
- 21. 奇怪的“未定义符号”错误?
- 22. 由CACurrentMediaTime引起的架构i386编译错误的未定义符号()
- 23. 编译错误:未定义的符号: “_main”,从引用:开始crt1.10.5.o
- 24. 编译与g ++,但仍然给出错误“未定义的符号:__gxx_personality_v0”
- 25. Ruby Tmail错误:未定义符号:rb_get_kcode
- 26. AOSP构建错误:未定义符号
- 27. SKPSMTP消息错误'未定义符号'
- 28. Xcode 4.3.3 - 错误未定义符号
- 29. 对createOpenGLCallback编译错误的未定义引用
- 30. 链接错误:未定义符号,其中很多(cpp交叉编译)
请参阅http://www.nasm.us/xdoc/2.10rc8/html/nasmdoc9.html#section-9.2.5(_库外的调用过程) – Michael