链接错误:"重定位R_X86_64_32...不能在制作共享对象时使用;重新编译时加上-fPIC"。

4

我正在尝试编译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

根据错误信息,我尝试使用fPIC来导出C++标志(export CXXFLAGS="$CXXFLAGS -fPIC"),通过向configure添加参数(./configure --enable-shared),并编辑Makefile(将CC = gcc改为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 ..

2
你在更改配置后清除了之前的构建吗?您可以检查日志以查看是否在编译标志中实际添加了“-fPIC”。 - Mine
@Mine 感谢您的评论。是的,我尝试了几次 make clean。在 config.log 中,我看到了关于 -fPIC 的引用,这表明它确实正在被使用(例如 checking if gcc PIC flag -fPIC -DPIC worksresult: yes 等)。 - d3pd
2个回答

0

配置脚本中一定有一个错误,它不应该出现 libvpx.a

但不用担心,因为Ubuntu提供了libvpx-devlibsodium-dev的软件包,并且使用这些软件包似乎可以正常工作,所以除非有强烈的理由不这样做,否则你应该只需这样做。

此外,除非你需要经典的toxcore,否则它的继承者c-toxcore似乎更好,所以你应该使用它。


超棒,安装 libvox-devlibsodium-dev 似乎已经成功了。谢谢! - d3pd

0

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接