如何建立并内置rpath的安装gcc? [英] How to build and install gcc with built-in rpath?
问题描述
我试图构建和安装自己的gcc 4.7.2在/ usr /本地到位在/ usr在gcc 4.4.6的使用。 (这是在CentOS 6.3)。
I'm trying to build and install my own gcc 4.7.2 in /usr/local to use in place of the gcc 4.4.6 in /usr. (This is on CentOS 6.3.)
GCC使得可执行文件和动态库动态链接到自己的动态库,例如的libstdc ++。所以。我该如何建立并安装GCC,以便生成的二进制文件自动获得,导致动态库在/ usr /本地/ lib64下要链接,而不是那些在/ usr /链接器-rpath选项(-rpath在/ usr /本地/ lib64下) lib64下或/ lib64目录?
gcc makes executables and dynamic libraries that dynamically link to its own dynamic libraries, e.g. libstdc++.so. How do I build and install gcc so that the generated binaries automatically get a linker -rpath option (-rpath /usr/local/lib64) that causes dynamic libraries in /usr/local/lib64 to be linked instead of those in /usr/lib64 or /lib64?
如果它工作正常,当我建立与海湾合作委员会的可执行文件,而无需指定-Wl,-rpath =的/ usr /本地/ lib64目录,当我的LDD可执行文件,它应该显示在/ usr /本地/ lib64目录/ ++的libstdc .so.6而不是/usr/lib64/libstdc++.so.6。同样,对于libgcc_s.so.1。
If it works properly, after I build an executable with the gcc without specifying "-Wl,-rpath=/usr/local/lib64", when I ldd the executable, it should show /usr/local/lib64/libstdc++.so.6 instead of /usr/lib64/libstdc++.so.6. Similarly for the libgcc_s.so.1.
我曾尝试不同的方法,包括指定LDFLAGS_FOR_TARGET = -Wl,-rpath =的/ usr /本地/ lib64下,-rpath =在/ usr / local / lib目录上的配置命令行,但毫无效果。
I have tried different approaches, including specifying LDFLAGS_FOR_TARGET=-Wl,-rpath=/usr/local/lib64,-rpath=/usr/local/lib on the 'configure' command-line, but nothing worked.
推荐答案
如果您不希望导出路径有一个替代的解决方案:
If you don't want to export paths there's an alternative solution:
你的 PATH工具链
:
gcc -dumpspecs > specsfile
修改 specsfile
节中的链接
添加 -rpath
例如:
*link:
%{!static:--eh-frame-hdr} -m %(link_emulation) %{shared:-shared} %{!shared: %{!static: %{rdynamic:-export-dynamic} -dynamic-linker %(dynamic_linker)} %{static:-static}} -rpath /usr/local/lib64
在这一点上,如果它与工作,你可以测试:
at this point you can test if it work with:
g++ -specs=specsfile test.cpp
readelf -d a.out |grep RPATH
如果它工作,你可以把它永久(无需通过 -specs
每次)
if it work you can make it permanent (no need to pass -specs
everytime)
strace -fF -o /tmp/g++.log g++ test.cpp
grep specs /tmp/g++.log
grep的应该显示的路径,其中 GCC
查找默认规格
文件。
借助规格文件非常灵活,允许根据条件链接变量,例如:
The specs files are flexible enough to allow conditional linking depending on variables, example:
{!static: %{mabi=n32:-rpath-link %R/lib32:%R/usr/lib32} %{mabi=64:-rpath-link %R/lib64:%R/usr/lib64} %{mabi=32:-rpath-link %R/lib:%R/usr/lib}}
应该使用依赖于多个不同的路径金马碧(未经测试,还),%R
应该是 SYSROOT
路径,可以使用所需的完整路径被改变。
should use different and multiple paths depending on mabi (untested, yet), %R
should be the sysroot
path, can be changed with needed full path.
还有一个 - 与-规格=
选项的 GCC配置最终将在构建时使用,不清楚我又如何与。链接
部分(它的工作)来使用
There's also a --with-specs=
option gcc configure eventually to be used at build time, not clear to me yet how to use with the .link
section (working on it)
--with-specs="%{shared:-Wl,-rpath -Wl,$(DESTDIR)/lib}%{!shared:-Wl,-rpath -Wl,$(DESTDIR)/lib}"
这工作,我同时使用共享
,而不是!共享
只是用于测试,可能是一些更聪明的条件应该是使用时,请注意,它不与 -dumpspecs
的报道。
It work, I used both shared
and not !shared
just for test, probably some smarter condition should be used, note that it isn't reported with -dumpspecs
.
通过gcc的邮件列表,我有IM pression 规格
不被大家所喜欢的某个线程读取(但如果我没看错4.9附加另一种选择 - 与 - 超规格
),而不是preferred办法做这样的自定义似乎是 configure.host
,但我做的,而不是寻找到它,玩得开心! : - )
Reading through some thread of the gcc mailing list I had the impression specs
aren't liked by everyone (but if I'm not wrong 4.9 add another option --with-extra-specs
) instead preferred way to do such customizations appears to be configure.host
, but I'm done and not looking into it, have fun! :-)
又见: gcc的常见问题解答rpath的
更新以上
我不知道你是否可以设置一个pre定义的 rpath的
,也许你可以将在链接 LD
的binutils
的不 GCC / G ++
,但为什么要这么做?
I don't know if you can set a pre-defined rpath
, probably if you can would be in the linker ld
of binutils
not in gcc/g++
, but why would you do that?
刚出口 LD_LIBRARY_PATH
在运行时和 LD_RUN_PATH
在构建时
Just export LD_LIBRARY_PATH
at runtime and LD_RUN_PATH
at build time
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
ldd a.out
LDD
应显示导出的路径。
要引用时共享库与内置的libtool给出的消息:
To quote a message given when a shared library is built with libtool:
如果你碰巧要在给定的目录,LIBDIR,您必须使用libtool的,对安装库链接,并指定库的完整路径,或在连接时使用`-LLIBDIR'标志,并做至少以下之一:
If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following:
- 执行过程中添加LIBDIR到'LD_LIBRARY_PATH'环境变量
- 连接过程中添加LIBDIR到`LD_RUN_PATH'环境变量
- 使用`轮候册, - rpath的轮候册,LIBDIR链接器标记
- 有您的系统管理员添加到LIBDIR /etc/ld.so.conf中`
请参阅任何操作系统文档有关的共享库
更多信息,如LD(1)和ld.so(8)手册页。
See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages.
完整性
在的Makefile
我用来测试的东西,所有的配置选项,环境变量(见启动LDFLAGS)我试过没有工作, - 启用-rpath
包括在内。
for completeness
the Makefile
I used for testing the thing, all the configure options, environment variables (see boot ldflags) I tried didn't work, --enable-rpath
included.
与使用的mkdir〜/ GCC
复制下面的的Makefile
到〜/ gcc的
然后 CD〜/ GCC和放大器;&安培;使堆积的gcc
的通知使用的选项仅适用于本次测试的情况下,不作为参考使用。
notice the options used are only for this test case, don't use as reference.
FETCH = aria2c --file-allocation=none -c -d dl
NICE = nice -n 19
PARALLEL = -j4
DESTDIR = $(HOME)/gcc/install
SRCDIR = $(HOME)/gcc/src
all:
# if more downloads are added just remove {dl,src}/*-my-stamp not the .bak
# the .bak should avoid to rebuild targets because of timestamp
touch_stamp = if [ -f $@.bak ]; then \
touch -r $@.bak $@; \
else \
touch $@ $@.bak; \
fi
dl/dl-my-stamp:
$(FETCH) https://ftp.gnu.org/gnu/gcc/gcc-4.7.2/gcc-4.7.2.tar.bz2
$(FETCH) http://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2
$(FETCH) ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
$(FETCH) https://ftp.gnu.org/gnu/mpfr/mpfr-2.4.2.tar.bz2
$(FETCH) --check-certificate=false http://www.mirrorservice.org/sites/sourceware.org/pub/binutils/snapshots/binutils-2.24.51.tar.bz2 \
ftp://sourceware.org/pub/binutils/snapshots/binutils-2.24.51.tar.bz2
$(touch_stamp)
untar_dep = src/untar-my-stamp
src/untar-my-stamp: dl/dl-my-stamp
mkdir -p src
tar -C src -xjf dl/gcc-4.7.2.tar.bz2
tar -C src -xjf dl/gmp-4.3.2.tar.bz2
tar -C src -xzf dl/mpc-0.8.1.tar.gz
tar -C src -xjf dl/mpfr-2.4.2.tar.bz2
tar -C src -xjf dl/binutils-2.24.51.tar.bz2
$(touch_stamp)
define configure-rule
$(1)_install = $(DESTDIR)/$(1)-install-my-stamp
$(1)_builddir = $$($(1)_dir)/build
$(DESTDIR)/$(1)-install-my-stamp: $$($(1)_deps)
mkdir -p $$($(1)_builddir)
cd $$($(1)_builddir) && \
$$($(1)_env) ../configure --cache-file=$(SRCDIR)/$(1)-config.cache \
$$($(1)_configure)
$(NICE) make -C $$($(1)_builddir) $$($(1)_make_target) $(PARALLEL)
ifneq ($$($(1)_post_make),)
$$($(1)_post_make)
endif
touch $$@
.PHONY: build-$(1) clean-$(1)
build-$(1): $$($(1)_install)
clean-$(1):
-rm -fr $$($(1)_builddir)
endef
gmp_dir = src/gmp-4.3.2
gmp_env = CONFIG_SITE=$(SRCDIR)/config.site
gmp_configure = --prefix=$(DESTDIR) \
--disable-shared --enable-static --enable-cxx
gmp_deps = $(untar_dep)
gmp_make_target = install
$(eval $(call configure-rule,gmp))
mpfr_dir = src/mpfr-2.4.2
mpfr_env = CONFIG_SITE=$(SRCDIR)/config.site
mpfr_configure = --prefix=$(DESTDIR) \
--disable-shared --enable-static \
--with-gmp=$(DESTDIR)
mpfr_deps = $(untar_dep) $(gmp_install)
mpfr_make_target = install
$(eval $(call configure-rule,mpfr))
mpc_dir = src/mpc-0.8.1
mpc_env = CONFIG_SITE=$(SRCDIR)/config.site
mpc_configure = --prefix=$(DESTDIR) \
--disable-shared --enable-static \
--with-gmp=$(DESTDIR) --with-mpfr=$(DESTDIR)
mpc_deps = $(untar_dep) $(gmp_install) $(mpfr_install)
mpc_make_target = install
$(eval $(call configure-rule,mpc))
gcc_dir = src/gcc-4.7.2
gcc_env = CONFIG_SITE=$(SRCDIR)/config.site \
CFLAGS="-I/usr/include/i386-linux-gnu" \
CXXFLAGS="-I/usr/include/i386-linux-gnu"
gcc_configure = --prefix=$(DESTDIR) \
--libdir=$(DESTDIR)/lib \
--with-local-prefix=$(DESTDIR) \
--with-gmp=$(DESTDIR) --with-mpfr=$(DESTDIR) \
--with-mpc=$(DESTDIR) \
--disable-bootstrap \
--enable-languages=c,c++ \
--disable-libgomp --disable-multilib \
--disable-libmudflap --disable-libssp \
--disable-libquadmath \
--enable-rpath \
MAKEINFO=missing
gcc_deps = $(untar_dep) $(gmp_install) $(mpfr_install) $(mpc_install)
gcc_make_target =
gcc_post_make = make -C $(gcc_builddir) install
$(eval $(call configure-rule,gcc))
binutils_dir = src/binutils-2.24.51
#binutils_env = LDFLAGS=-Wl,-rpath\ $(DESTDIR)/lib
binutils_env = CONFIG_SITE=$(SRCDIR)/config.site \
CFLAGS="-I/usr/include/i386-linux-gnu" \
BOOT_LDFLAGS="-rpath-link=$(DESTDIR)/lib -rpath=$(DESTDIR)/lib"
binutils_configure = --prefix=$(DESTDIR) \
--libdir=$(DESTDIR)/lib \
--with-gmp=$(DESTDIR) \
--enable-rpath
binutils_deps = $(untar_dep) $(gmp_install)
#binutils_make_target = install
binutils_post_make = make -C $(binutils_builddir) install
$(eval $(call configure-rule,binutils))
.PHONY: env
env:
@echo export PATH=$(DESTDIR)/bin:\$$PATH
@echo export LIBRARY_PATH=/usr/lib/i386-linux-gnu
这篇关于如何建立并内置rpath的安装gcc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!