我正在尝试使用自定义前缀构建 gcc 4.7.2 $PREFIX
我已将所有先决条件构建并安装到我的前缀位置,然后成功配置、构建并安装了 gcc。
我现在遇到的问题是 $PREFIX
不在库搜索路径中,因此找不到共享库。
$PREFIX/bin $ ./g++ ~/main.cpp
$PREFIX/libexec/gcc/x86_64-suse-linux/4.7.2/cc1plus: \
error while loading shared libraries: \
libcloog-isl.so.1: \
cannot open shared object file: No such file or directory
有效但不理想的方法
如果我 export LD_LIBRARY_PATH=$PREFIX/lib
那么它就可以工作,但我正在寻找不需要设置环境变量就可以工作的东西。
如果我使用 patchelf
在所有 gcc
二进制文件上设置 RPATH
那么它也可以工作;然而,这涉及搜索所有 elf 二进制文件并调用 patchelf
迭代它们,我宁愿有更永久的东西。
我认为最适合我的目的
所以我希望有一种方法可以在构建过程中将 -Wl,-rpath,$PREFIX/lib
传递给 make。
因为我知道不需要更改路径,所以这似乎是最可靠的解决方案,也可以在我们构建下一个 gcc 版本时使用。
是否可以将构建过程配置为对 RPATH
进行硬编码?
我已经尝试过,但不起作用
在调用 configure
之前设置 LDFLAGS_FOR_TARGET
:
所有这些都失败了:
export LDFLAGS_FOR_TARGET="-L$PREFIX/lib -R$PREFIX/lib"
export LDFLAGS_FOR_TARGET="-L$PREFIX/lib"
export LDFLAGS_FOR_TARGET="-L$PREFIX/lib -Wl,-rpath,$PREFIX/lib"
在调用 configure
之前设置 LDFLAGS
:
export LDFLAGS="-L$PREFIX/lib -Wl,-rpath,$PREFIX/lib"
无论如何,我担心这些会覆盖任何 LDFLAGS
gcc 会 已经拥有的,所以我不确定这些是否是一个可行的选择,即使它们可以可以工作吗?
我的配置行
为了完整起见,这里是我传递给配置的行:
./configure \
--prefix=$PREFIX \
--build=x86_64-suse-linux \
--with-pkgversion='SIG build 12/10/2012' \
--disable-multilib \
--enable-cloog-backend=isl \
--with-mpc=$PREFIX \
--with-mpfr=$PREFIX \
--with-gmp=$PREFIX \
--with-cloog=$PREFIX \
--with-ppl=$PREFIX \
--with-gxx-include-dir=$PREFIX/include/c++/4.7.2
最佳答案
我发现将 gmp、mpfr、mpc、isl、cloog 等的源目录复制到顶级 gcc 源目录(或使用具有相同名称的符号链接(symbolic link))在任何地方都有效。这实际上是首选方式。
您需要复制(或链接)到这些源目录名称不带版本号才能正常工作。
编译器不需要 LD_LIBRARY_PATH(尽管使用编译器构建的运行应用程序将需要 LD_LIBRARY_PATH 到 $PREFIX/lib64 或类似的东西 - 但这是不同的)
从一个源代码目录开始,您将在其中保存所有源代码。 在此源目录中,您可以通过解压缩 tarball 或 svn 来获得 gcc 目录... 我使用颠覆。
同样在这个顶级目录中,例如,以下源代码包:
gmp-5.1.0.tar.bz2
mpfr-3.1.1.tar.bz2
mpc-1.0.1.tar.gz
isl-0.11.1.tar.bz2
cloog-0.18.0.tar.gz
我只是下载这些并定期更新到最新的压缩包。
以脚本形式:
# Either:
svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc_work
# Or:
bunzip -c gcc-4.8.0.tar.bz2 | tar -xvf -
mv gcc-4.8.0 gcc_work
# Uncompress sources.. (This will produce version numbered directories).
bunzip -c gmp-5.1.0.tar.bz2 | tar -xvf -
bunzip -c mpfr-3.1.1.tar.bz2 | tar -xvf -
gunzip -c mpc-1.0.1.tar.gz | tar -xvf -
bunzip -c isl-0.11.1.tar.bz2 | tar -xvf -
gunzip -c cloog-0.18.0.tar.gz | tar -xvf -
# Link outside source directories into the top level gcc directory.
cd gcc_work
ln -s ../gmp-5.1.0 gmp
ln -s ../mpfr-3.1.1 mpfr
ln -s ../mpc-1.0.1 mpc
ln -s ../isl-0.11.1 isl
ln -s ../cloog-0.18.0 cloog
# Get out of the gcc working directory and create a build directory. I call mine obj_work.
# I configure the gcc binary and other outputs to be bin_work in the top level directory. Your choice. But I have this:
# home/ed/projects
# home/ed/projects/gcc_work
# home/ed/projects/obj_work
# home/ed/projects/bin_work
# home/ed/projects/gmp-5.1.0
# home/ed/projects/mpfr-3.1.1
# home/ed/projects/mpc-1.0.1
# home/ed/projects/isl-0.11.1
# home/ed/projects/cloog-0.18.0
mkdir obj_work
cd obj_work
../gcc_work/configure --prefix=../bin_work <other options>
# Your <other options> shouldn't need to involve anything about gmp, mpfr, mpc, isl, cloog.
# The gcc build system will find the directories you linked,
# then configure and compile the needed libraries with the necessary flags and such.
# Good luck.
关于c++ - 如何在 Bootstrap 期间在 gcc 二进制文件上设置 rpath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13813737/