本文介绍了将g ++ 4.8链接到libstdc ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在我的桌面上下载并构建了gcc 4.8.1,运行64位Ubuntu 12.04。我建立它的源,像文档推荐,并用命令 ../../ gcc-4.8。 1 / configure --prefix = $ HOME --program-suffix = -4.8 make make -k check make install 它似乎通过了所有的测试,我将所有的东西都安装到我的主目录下,后缀为-4.8,以区别于系统gcc,它是版本4.6.3 。不幸的是,当我使用g ++ - 4.8编译c ++程序时,它链接到系统libc和libstdc ++,而不是从gcc-4.8.1编译的新程序。我下载并构建了gcc 4.8,因为我想在标准库中使用新的C ++ 11功能,所以这种行为绝对不是我想要的。我能做什么让gcc-4.8自动链接到它附带的标准库而不是系统标准库? 解决方案当你链接到自己的gcc,你需要添加一个额外的运行时链接器搜索路径 -Wl,-rpath,$(PREFIX)/ lib64 ,以便在运行时找到与您的gcc对应的共享库。 我通常在与相同的目录下创建一个名为 gcc 和 g ++ 我调用了gcc-4.8 和 g ++ - 4.8 ,而不是 gcc-4.8 code> g ++ - 4.8 ,如动态链接器无法查找GCC库: #!/ bin / bash exec $ {0} SUFFIX - Wl,-rpath,PREFIX / lib64$ @ 安装 SUFFIX 和 PREFIX 应替换为传递给 configure : cd $ {PREFIX} / bin&& rm -f gcc g ++ c ++ gfortran sed -e'##PREFIX#$ {PREFIX} #g'-e's#SUFFIX#$ {SUFFIX} #g'gcc-wrapper.sh> $ {PREFIX} / bin / gcc chmod + x $ {PREFIX} / bin / gcc cd $ {PREFIX} / bin&& ln gcc g ++&& ln gcc c ++&&& ln gcc gfortran ( gcc-wrapper.sh 上述解决方案不适用于某些版本的 libtool ,因为 g ++ -Wl,... -v 假定为链接模式,并且失败并显示错误。 $ b b 更好的解决方案是使用specs文件。一旦gcc / g ++被构建,调用以下命令使gcc / g ++添加 -rpath 到链接器命令行(替换 $ {PREFIX} / lib64 ): g ++ -dumpspecs | awk'/ ^ \ * link:/ {print; getline; print-rpath = $ {PREFIX} / lib64,$ 0; next} {print}'> $(dirname $(g ++ -print-libgcc-file-name))/ specs I downloaded and built gcc 4.8.1 on my desktop, running 64-bit Ubuntu 12.04. I built it out of source, like the docs recommend, and with the commands../../gcc-4.8.1/configure --prefix=$HOME --program-suffix=-4.8makemake -k checkmake installIt seemed to pass all the tests, and I installed everything into my home directory w/ the suffix -4.8 to distinguish from the system gcc, which is version 4.6.3.Unfortunately when I compile c++ programs using g++-4.8 it links to the system libc and libstdc++ rather than the newer ones compiled from gcc-4.8.1. I downloaded and built gcc 4.8 because I wanted to play around with the new C++11 features in the standard library, so this behaviour is definitely not what I wanted. What can I do to get gcc-4.8 to automatically link to the standard libraries that came with it rather than the system standard libraries? 解决方案 When you link with your own gcc you need to add an extra run-time linker search path(s) with -Wl,-rpath,$(PREFIX)/lib64 so that at run-time it finds the shared libraries corresponding to your gcc.I normally create a wrapper named gcc and g++ in the same directory as gcc-4.8 and g++-4.8 which I invoke instead of gcc-4.8 and g++-4.8, as prescribed in Dynamic linker is unable to find GCC libraries:#!/bin/bashexec ${0}SUFFIX -Wl,-rpath,PREFIX/lib64 "$@"When installing SUFFIX and PREFIX should be replaced with what was passed to configure:cd ${PREFIX}/bin && rm -f gcc g++ c++ gfortransed -e 's#PREFIX#${PREFIX}#g' -e 's#SUFFIX#${SUFFIX}#g' gcc-wrapper.sh > ${PREFIX}/bin/gccchmod +x ${PREFIX}/bin/gcccd ${PREFIX}/bin && ln gcc g++ && ln gcc c++ && ln gcc gfortran(gcc-wrapper.sh is that bash snippet).The above solution does not work with some versions of libtool because g++ -Wl,... -v assumes linking mode and fails with an error.A better solution is to use specs file. Once gcc/g++ is built, invoke the following command to make gcc/g++ add -rpath to the linker command line (replace ${PREFIX}/lib64 as necessary):g++ -dumpspecs | awk '/^\*link:/ { print; getline; print "-rpath=${PREFIX}/lib64", $0; next } { print }' > $(dirname $(g++ -print-libgcc-file-name))/specs 这篇关于将g ++ 4.8链接到libstdc ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-01 21:52