编译失败并出现“在制作共享对象时无法使用针对 `.rodata.str1.8' 的重定位 R_X86_64_32" [英] Compilation fails with "relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object"

查看:25
本文介绍了编译失败并出现“在制作共享对象时无法使用针对 `.rodata.str1.8' 的重定位 R_X86_64_32"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 VPS 中的 makefile 编译此源代码,但它不起作用.VPS 是 64 美分操作系统

I'm trying to compile this source code from the makefile in a VPS, but its not working. The VPS is a 64 Cent OS

这是完整的错误

# make
gcc -c -O3 -w -DLINUX -I../SDK/amx/ ../SDK/amx/*.c
g++ -c -O3 -w -DLINUX -I../SDK/amx/ ../SDK/*.cpp
g++ -c -O3 -w -DLINUX -I../SDK/amx/ *.cpp
g++ -O2 -fshort-wchar -shared -o "TCP_V1.so" *.o
/usr/bin/ld: TCP-LINUX_V1.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be     used when making a shared object; recompile with -fPIC
TCP-LINUX_V1.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [all] Error 1

这是我的生成文件:

GPP=g++
GCC=gcc
OUTFILE="TCP_V1.so"

COMPILE_FLAGS=-c -O3 -w -DLINUX -I../SDK/amx/

all:
    $(GCC) $(COMPILE_FLAGS) ../SDK/amx/*.c
    $(GPP) $(COMPILE_FLAGS) ../SDK/*.cpp
    $(GPP) $(COMPILE_FLAGS) *.cpp
    $(GPP) -O2 -fshort-wchar -shared -o $(OUTFILE) *.o

有人知道怎么回事吗?

推荐答案

按照编译器告诉你的去做,即用 -fPIC 重新编译.要了解此标志的作用以及在这种情况下为什么需要它,请参阅 GCC 手册的代码生成选项.

Do what the compiler tells you to do, i.e. recompile with -fPIC. To learn what does this flag do and why you need it in this case, see Code Generation Options of the GCC manual.

简而言之,术语位置无关代码 (PIC) 是指生成的与内存地址无关的机器代码,即不对其加载到 RAM 的位置做出任何假设.只有与位置无关的代码才应该包含在共享对象 (SO) 中,因为它们应该能够动态更改其在 RAM 中的位置.

In brief, the term position independent code (PIC) refers to the generated machine code which is memory address agnostic, i.e. does not make any assumptions about where it was loaded into RAM. Only position independent code is supposed to be included into shared objects (SO) as they should have an ability to dynamically change their location in RAM.

最后,您也可以在 Wikipedia 上了解它.

Finally, you can read about it on Wikipedia too.

这篇关于编译失败并出现“在制作共享对象时无法使用针对 `.rodata.str1.8' 的重定位 R_X86_64_32"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆