“重定位R_X86_64_32S”链接错误 [英] "relocation R_X86_64_32S against " linking Error

查看:1741
本文介绍了“重定位R_X86_64_32S”链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将静态库链接到共享库,我收到以下错误

I'm Trying to Link a static Library to a shared library , I'm Getting the Following error


/usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(fileappender.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC
../../../libraries/log4cplus/liblog4cplus.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

但是这在32位机器上没有任何这样的错误。我尝试手动添加 -fPIC 标志到Makefile也没有解决问题

But this worked on a 32bit machine without any such error. I tried adding The -fPIC flags manually to the Makefile that too didn't solve the problem

我试过 -whole-archive 标记为建议这里,但没有成功。

I tried the -whole-archive flag as suggested here but with no success.

 
/usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(appenderattachableimpl.o): relocation R_X86_64_32S against `vtable for log4cplus::spi::AppenderAttachable' can not be used when making a shared object; recompile with -fPIC
../../../libraries/log4cplus/liblog4cplus.a(appenderattachableimpl.o): could not read symbols: Bad value
collect2: ld returned 1 exit status



创建liblog4cplus.a:



Creation of liblog4cplus.a:


  1. unzip log4cplus-1.1.0.zip

  2. ./ configure --enable-static = yes --enable- threads = yes

  3. vi Makefile 并将-fPIC添加到CXXFLAGS和CFLAGS

  4. make

  1. unzip log4cplus-1.1.0.zip
  2. ./configure --enable-static=yes --enable-threads=yes
  3. vi Makefile and added -fPIC to CXXFLAGS and CFLAGS
  4. make



然后编译我的共享库: / h3>

Then for Compiling my shared library:


  1. g ++ -frtti -w -c -fPIC -IInclude_Directorymyfile.cpp

  2. g ++ -shared -fPIC -frtti -IInclude_Directory-o mysofile.so myfile.o -Wl, - whole-archive../ ../../libraries/log4cplus/liblog4cplus.a-Wl, - no-whole-archive -ldl

  1. g++ -frtti -w -c -fPIC -I"Include_Directory" myfile.cpp
  2. g++ -shared -fPIC -frtti -I"Include_Directory" -o mysofile.so myfile.o -Wl,--whole-archive "../../../libraries/log4cplus/liblog4cplus.a" -Wl,--no-whole-archive -ldl


推荐答案

假设你正在生成一个共享库,很可能发生的是, liblog4cplus.a 的变体正在使用未使用 -fPIC 编译。在linux中,您可以通过从静态库和检查其重新定位

Assuming you are generating a shared library, most probably what happens is that the variant of liblog4cplus.a you are using wasn't compiled with -fPIC. In linux, you can confirm this by extracting the object files from the static library and checking their relocations:

ar -x liblog4cplus.a  
readelf --relocs fileappender.o | egrep '(GOT|PLT|JU?MP_SLOT)'

如果输出为空,库不是位置无关的,不能用于生成共享对象。

If the output is empty, then the static library is not position-independent and cannot be used to generate a shared object.

由于静态库包含已编译的对象代码,因此提供-fPIC标志, t帮助。

Since the static library contains object code which was already compiled, providing the -fPIC flag won't help.

您需要查看使用 -fPIC编译的 liblog4cplus.a 版本,然后改用它。

You need to get ahold of a version of liblog4cplus.a compiled with -fPIC and use that one instead.

这篇关于“重定位R_X86_64_32S”链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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