在制作共享对象时,不能使用针对`.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"

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

问题描述

我试图从VPS中的makefile编译这个源代码,但它不工作。 VPS是一个64 Cent操作系统



这里是完整的错误

  #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 -oTCP_V1.so* .o
/ usr / bin / ld:TCP-LINUX_V1.o:对于`.rodata.str1.8'重定位R_X86_64_32不能在创建共享对象时使用;重新编译-fPIC
TCP-LINUX_V1.o:无法读取符号:错误值
collect2:ld返回1退出状态
make:*** [all]错误1

这是我的makefile:

  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
解决方案

p>做编译器告诉你做的事情,即使用 -fPIC 重新编译。要了解此标记的作用以及为什么在这种情况下需要它,请参阅

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



最后,您可以阅读 维基百科


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

Here's the full error

# 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

Here's my makefile:

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

Anyone know what's wrong?

解决方案

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.

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.

Finally, you can read about it on Wikipedia too.

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

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