CentOS 5 上编译安装 GCC

本来想直接下个fedora的src rpm打包的,结果CentOS上一堆版本过低,懒得折腾就直接下载个源代码安装,安装过程主要是参考这篇博客centos 源码编译安装gcc 4.7.0。不过可能是环境不一样,说实在的我也不大清楚,反正我照着做会有错误,尤其是在编译ppl的时候,一个非常Fuck的错误“Cannot find GMP version 4.1.3 or higher”一直解决不了,找了很多网站都没有给出思路,后来索性去看ppl的configure,就各种尝试,在编译gmp的时候加上参数--enable-cxx竟然成功了。懒得再深究原因了。我把我的编译命令直接放在本文,具体不多解释了。

wget http://gcc.petsads.us/releases/gcc-4.7.1/gcc-4.7.1.tar.gz
wget http://gcc.petsads.us/infrastructure/cloog-0.16.2.tar.gz
wget http://gcc.petsads.us/infrastructure/mpc-0.8.1.tar.gz
wget http://gcc.petsads.us/infrastructure/mpfr-2.4.2.tar.bz2
wget http://gcc.petsads.us/infrastructure/ppl-0.11.tar.gz
wget ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.5.tar.bz2

yum install m4 gcc-c++ 

tar jxvf gmp-4.3.2.tar.bz2
cd gmp-4.3.2
./configure --enable-cxx && make && make install

tar jxvf mpfr-2.4.2.tar.bz2 
cd mpfr-2.4.2
./configure --with-gmp=/usr/local && make && make install

tar zxvf mpc-0.8.1.tar.gz
cd mpc-0.8.1
./configure --with-gmp=/usr/local --with-mpfr=/usr/local
make && make install

tar zxvf ppl-0.11.tar.gz
cd ppl-0.11
./configure --with-gmp=/usr/local --enable-cxx

tar zxvf cloog-0.16.2.tar.gz
cd cloog-0.16.2
./configure --prefix=/usr/local --with-gmp=/usr/local
make && make install

/sbin/ldconfig -v

tar zxvf gcc-4.7.1.tar.gz
cd gcc-4.7.1
./configure --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --enable-languages=c,c++ --enable-threads=posix --enable-__cxa_atexit --with-cpu=generic --disable-multilib --with-ppl=/usr/local --with-cloog=/usr/local --enable-cloog-backend=isl
make && make install

另外在编译ppl的时候,在最后一步出现一个错误:

/bin/sh: line 1 11177 killed
 /usr/bin/m4 --prefix-builtin -I.. -I. -I./.. ./ppl_interface_generator_c_h.m4 > ppl_c_domains.h

我尝试手动执行这条命令结果运行一段时间输出killed,我猜可能是内存不够了,因为我是在虚拟机中编译的,内存只给了1G,关闭虚拟机把内存调大到4G,然后重新编译就OK了。

总之编译gcc这种事太蛋疼了,还是用yum安装好,哎。

Ubuntu上手动编译的一篇文章:http://solarianprogrammer.com/2012/04/13/building-gcc-4-7-on-ubuntu-12-04/