【问题标题】:Linking error: "relocation R_X86_64_32 ... can not be used when making a shared object; recompile with -fPIC"链接错误:“重定位 R_X86_64_32 ... 制作共享对象时无法使用;使用 -fPIC 重新编译”
【发布时间】:2016-11-16 21:47:17
【问题描述】:

我正在尝试编译 Tox(特别是 toxcore)。当我尝试编译它时,遇到以下错误:

>make
make  all-recursive
make[1]: Entering directory '/root/Tox/toxcore'
Making all in build
make[2]: Entering directory '/root/Tox/toxcore/build'
  CCLD     libtoxav.la
/usr/bin/ld: /usr/local/lib/libvpx.a(vpx_codec.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libvpx.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:1385: recipe for target 'libtoxav.la' failed
make[2]: *** [libtoxav.la] Error 1
make[2]: Leaving directory '/root/Tox/toxcore/build'
Makefile:506: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/root/Tox/toxcore'
Makefile:410: recipe for target 'all' failed
make: *** [all] Error 2

根据错误消息,我尝试通过导出 C++ 标志 (export CXXFLAGS="$CXXFLAGS -fPIC")、向 configure (./configure --enable-shared) 添加参数和编辑 Makefile(更改 @987654327)来使用 fPIC @ to CC = gcc -fPIC),但是这些尝试都没有奏效,我仍然遇到同样的错误。可能出了什么问题?

这是我现在的方法(在 Ubuntu 上):

sudo apt-get install pkg-config
sudo apt-get install build-essential
sudo apt-get install libtool
sudo apt-get install autotools-dev
sudo apt-get install automake
sudo apt-get install checkinstall
sudo apt-get install check
sudo apt-get install git
sudo apt-get install yasm

cd ~
mkdir Tox
cd Tox

git clone https://github.com/jedisct1/libsodium.git
cd libsodium
git checkout tags/1.0.3
./autogen.sh
./configure && make check
sudo checkinstall --install --pkgname libsodium --pkgversion 1.0.0 --nodoc
sudo ldconfig
cd ..

git clone https://chromium.googlesource.com/webm/libvpx
cd libvpx
git checkout tags/v1.3.0
./configure
make
make install
cd ..

git clone https://github.com/irungentoo/toxcore.git
cd toxcore
autoreconf -i
./configure
make
sudo make install
cd ..

【问题讨论】:

  • 您在更改配置后是否清理了先前的构建?您可以查看日志,看看您是否真的在编译标志中附加了-fPIC
  • @Mine 感谢您的评论。是的,我尝试了一些清洁。在config.log 中,我看到对-fPIC 的引用表明它确实正在被使用(例如checking if gcc PIC flag -fPIC -DPIC worksresult: yes 等)。

标签: c++ gcc tox fpic


【解决方案1】:

配置脚本肯定有bug,不应该出现libvpx.a

但不要担心,因为 Ubuntu 为 libvpx-devlibsodium-dev 提供了软件包,并且使用它们似乎工作得很好,所以你可能应该这样做,除非有充分的理由不这样做。

此外,除非您需要经典的toxcore,否则c-toxcore 似乎是继任者,因此您可能应该改用它。

【讨论】:

  • 超级,libvox-devlibsodium-dev 的安装似乎有效。谢谢!
【解决方案2】:

使用--enable-pic 进行配置将添加必要的 -fPIC 选项,并且对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 2017-05-22
    • 1970-01-01
    相关资源
    最近更新 更多