本文参考:http://blog.163.com/phys_atom/blog/static/1676445532012229814992/
如果直接使用GUN GCC官方的源码来安装是不成功的,因为源码需要编译,编译要使用GCC,进入死循环,
所以需要先安装GCC的RPM包,这文件在RHEL系统光盘里Packages下有(这里使用i386盘),由于gcc需要依赖其他库,所以需要先安装其他文件,
如果你的环境与这里的不一样,根据错误信息安装所依赖的库就行,安装确实是有点麻烦,
安装顺序为:
1. rpm -ihv kernel-headers-2.6.32-279.el6.i686.rpm
2. rpm -ihv glibc-headers-2.12-1.80.el6.i686.rpm
3. rpm -ihv glibc-devel-2.12-1.80.el6.i686.rpm
4. rpm -ihv mpfr-2.4.1-6.el6.i686.rpm
5. rpm -ihv ppl-0.10.2-11.el6.i686.rpm
6. rpm -ihv cpp-4.4.6-4.el6.i686.rpm
7. rpm -ihv cloog-ppl-0.15.7-1.2.el6.i686.rpm
8. rpm -ihv gcc-4.4.6-4.el6.i686.rpm
安装低版本的gcc后可以安装高版本,这里使用的是gcc-4.7.2.tar.gz,进入gcc路径后使用./configure -prefix /usr/local/gcc-4.7.2/
一般会出现错误:
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations. Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.
说明gcc需要以来GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+
所以需要去gcc官方下载相应包:ftp://gcc.gnu.org/pub/gcc/infrastructure/
先安装GMP,其次MPFR,最后才是MPC
1. tar jxvf gmp-4.3.2.tar.bz2
2.mkdir /usr/local/gmp-4.3.2
3. ./configure --prefix=/usr/local/gmp-4.3.2/
4. make
5. make install
MPFR安装:
1 . tar jxvf mpfr-2.4.2.tar.bz2
2. mkdir /usr/local/mpfr-2.4.2
3. ./configure --prefix=/usr/local/mpfr-2.4.2/ --with-gmp=/usr/local/gmp-4.3.2/ ##这里需要加入gmp库路径
4.make
5.make install
MPC安装:
1. tar zxvf mpc-0.8.1.tar.gz
2. mkdir /usr/local/mpc-0.8.1
3. ./configure --prefix=/usr/local/mpc-0.8.1/ --with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/
接下来进入gcc目录:
1. ./configure --prefix=/usr/local/gcc-4.7.2/ -enable-threads=posix -disable-checking -disable-mutilib -enable-languages=c,c++,java --with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/ --with-mpc=/usr/local/mpc-0.8.1/
2. make后出现两个错误,解决办法:添加环境变量:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib
然后再执行make,的确你可以去做其他事情了,这个需要时间比较长
3.获取你会碰到错误gcc/lto-compress.c:28:18: fatal error: zlib.h: No such file or direct,那你得安装rpm -ivh zlib-devel-1.2.3-27.el6.i686.rpm
4. 现在可以make了 然后make install,如果不出意外,安装就能成功