我尝试在/usr/local中构建和安装我自己的gcc 4.7.2,以代替/usr中的gcc 4.4.6。(这是在CentOS 6.3上。)
gcc创建了可执行文件和动态库,它们动态链接到自己的动态库,例如libstdc++. so。如何构建和安装gcc,以便生成的二进制文件自动获得链接器-rpath选项(-rpath /usr/local/lib 64),该选项会导致链接/usr/local/lib 64中的动态库,而不是链接/usr/lib 64或/lib 64中的动态库?
如果它工作正常,在我使用gcc构建一个可执行文件而不指定“-Wl,-rpath=/usr/local/lib 64”之后,当我ldd该可执行文件时,它应该显示/usr/local/lib 64/libstdc++.so.6而不是/usr/lib 64/libstdc++.so.6。libgcc_s.so.1也是如此。
我尝试了不同的方法,包括在'configure'命令行上指定LDFLAGS_FOR_TARGET=-Wl、-rpath=/usr/local/lib 64、-rpath=/usr/local/lib,但没有任何效果。
2条答案
按热度按时间o0lyfsai1#
如果您不想导出路径,还有一个替代解决方案:
PATH
中的工具链:编辑
specsfile
,并在link
部分中添加-rpath
示例:此时,您可以测试它是否与以下各项一起工作:
如果它工作,您可以使它成为永久(不需要每次都传递
-specs
)grep应该显示
gcc
查找默认specs
文件的路径。specs文件非常灵活,允许根据变量进行条件链接,例如:
应根据mabi使用不同的多个路径(尚未测试),
%R
应为sysroot
路径,可根据需要更改为完整路径。还有一个
--with-specs=
选项gcc configure最终将在构建时使用,我还不清楚如何与link
部分一起使用(正在研究)。它起作用了,我使用了
shared
而不是!shared
只是为了测试,可能应该使用一些更聪明的条件,请注意,它没有与-dumpspecs
一起报告。通过阅读一些线程的gcc邮件列表,我有印象
specs
不是每个人都喜欢(但如果我没有错4.9添加另一个选项--with-extra-specs
),而不是首选的方式来做这样的自定义似乎是configure.host
,但我做了,不看它,玩得开心!:-)另请参阅:gcc常见问题解答rpath
更新以上内容
我不知道你是否可以设置一个预定义的
rpath
,如果你可以的话,可能会在binutils
的链接器ld
中,而不是在gcc/g++
中,但是你为什么要这样做呢?只需在运行时导出
LD_LIBRARY_PATH
,在构建时导出LD_RUN_PATH
ldd
应该会显示您汇出的路径。引用使用libtool构建共享库时给出的一条消息:
如果你想链接到一个指定目录LIBDIR中的已安装库,你必须使用libtool,并指定库的完整路径名,或者在链接过程中使用'-LLIBDIR'标志,并至少执行以下操作之一:
有关更多信息,请参见有关共享库的任何操作系统文档,如ld(1)和ld.so(8)手册页。
为了完整性我用于测试的
Makefile
、所有配置选项、环境变量(请参见 Boot ldflags)都不起作用,包括--enable-rpath
。与
mkdir ~/gcc
一起使用将下面的Makefile
复制到~/gcc
,然后复制到cd ~/gcc && make build-gcc
注意所使用的选项仅针对本测试用例,不作为参考使用。
dhxwm5r42#
我正在安装httpd-2.4.51,需要指定-rpath来编译程序。我使用链接器标志
-Wl,-rpath -Wl,LIBDIR
。使用命令:
您可以检查gcc的安装位置:
gcc: /usr/bin/gcc /usr/lib/gcc /usr/share/man/man1/gcc.1.gz
个