在OS X 10.9中构建GCC 4.8.2

3

我正在尝试在OS X 10.9中编译和安装GCC 4.8.2。我按照这里的说明 (http://gcc.gnu.org/wiki/InstallingGCC),首先运行./contrib/download_prerequesites,然后从与源代码不同的目录运行configure和make。我的构建失败并显示以下错误:

checking for suffix of object files... configure: error: in `/Users/prokilogrammer/temp/gcc-build482/x86_64-apple-darwin13.0.2/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.

显然,如果GCC的依赖项(GMP、MPC、MPFR)正确安装,这个问题就会得到解决(http://gcc.gnu.org/wiki/FAQ#configure_suffix)。我检查并确保它们已经正确地安装在/usr/local/lib和/usr/local/include目录下。
查看config.log,我看到以下错误:
configure:3565: checking for suffix of object files
configure:3587: /Users/prokilogrammer/temp/gcc-build482/./gcc/xgcc -B/Users/prokilogrammer/temp/gcc-build482/./gcc/ -B/usr/local/x86_64-apple-darwin13.0.2/bin/ -B/usr/local/x86_64-apple-darwin13.0.2/lib/ -isystem /usr/local/x86_64-apple-darwin13.0.2/include -isystem /usr/local/x86_64-apple-darwin13.0.2/sys-include    -c -g -O2  conftest.c >&5
conftest.c:1:0: internal compiler error: Segmentation fault: 11
 /* confdefs.h */
 ^
libbacktrace could not find executable to open

我不确定segmentation fault是由于缺少依赖项还是gcc中的合法问题。

你们有没有遇到类似的问题?是否有解决方法或变通之道?

附注:我也尝试了设置LD_LIBRARY_PATH和DYLD_LIBRARY_PATH,但没有任何运气。

1个回答

3

我在几台Mavericks机器上构建了GCC 4.8.2,但是我选择了略微不同的策略。具体来说,我在构建目录中包含了GMP、MPC、MPFR(以及CLOOG和ISL)的代码。我使用一个脚本来实现准自动化:

GCC_VER=gcc-4.8.2
tar -xf ${GCC_VER}.tar.bz2 || exit 1

cd ${GCC_VER} || exit

cat <<EOF |
    cloog 0.18.0 tar.gz 
    gmp 5.1.3 tar.xz 
    isl 0.11.1 tar.bz2 
    mpc 1.0.1 tar.gz 
    mpfr 3.1.2 tar.xz
EOF

while read file vrsn extn
do
    tar -xf "../$file-$vrsn.$extn" &&
    ln -s "$file-$vrsn" "$file"
done

完成上述操作后:
mkdir gcc-4.8.2-obj
cd gcc-4.8.2-obj
../gcc-4.8.2/configure --prefix=$HOME/gcc/v4.8.2
make -j8 bootstrap

据我所知,这就是需要的全部内容,使用4.8.1和4.8.2版本即可。

感谢您的指导。我按照您的指示操作了,但是没有成功。我仍然遇到相同的错误。我不确定我的环境出了什么问题,导致事情变得混乱。 - isEmpty
很遗憾听到这个消息。你预装了哪个编译器?我当时用的是XCode 5。你能否用那个编译器编译任何代码吗?我没有任何/ usr / local / x86_64-apple-darwin13.0.2目录。这是否意味着你之前使用过GCC编译器? - Jonathan Leffler
哎呀,我之前在十月份就已经进行了构建,但现在看到的是darwin12.x而不是13.x,这表明它是针对Mountain Lion而不是Mavericks的构建。所以,我已经将GCC 4.8.2移开,并重新进行了配置等操作,使用XCode gcc进行引导阶段。我正在使用上述脚本,将两个片段结合起来。目前为止,一切都很顺利...我正在追踪它。 - Jonathan Leffler
在一台拥有16 GiB RAM和SSD驱动器的机器上,编译花费了约45分钟,但是在我的机器上,使用苹果提供的'gcc'(其中'/usr/bin/gcc -version '说:Configured with: --prefix = /Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) Target: x86_64-apple-darwin13.0.0 Thread model: posix)来引导构建,最终成功完成编译。 - Jonathan Leffler
其实是的。我刚意识到我安装了osx-gcc-installer,这个工具启动了gcc编译。我没有意识到这个包在10.9上不受官方支持。我卸载了这个包并安装了XCode。现在我可以很好地编译gcc :) 感谢您的帮助。 PS:顺便说一下,这次我使用Home Brew来编译gcc。 - isEmpty

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