因为某些软件需要高版本的gcc,可以按照需求升级到gcc4.6或者gcc4.8。
一、编码编译安装gcc4.6
1、查看当前操作系统版本
[root@master ~]# gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
2、下载gcc、gmp和mpfr
[root@master ~]# wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.bz2
[root@master ~]# wget ftp://gcc.gnu.org/pub/gcc/infrastructure/{gmp-4.3.2.tar.bz2,mpc-0.8.1.tar.gz,mpfr-2.4.2.tar.bz2}
3、编译gmp
[root@master ~]# tar -jxf gmp-4.3.2.tar.bz2
[root@master ~]# cd gmp-4.3.2
[root@master gmp-4.3.2]# ./configure --prefix=/usr/local/gmp
[root@master gmp-4.3.2]# make &&make install
4、编译mpfr
[root@master ~]# tar -jxf mpfr-2.4.2.tar.bz2
[root@master ~]# cd mpfr-2.4.2
[root@master mpfr-2.4.2]# ./configure --prefix=/usr/local/mpfr -with-gmp=/usr/local/gmp
[root@master mpfr-2.4.2]# make &&make install
5、编译mpc
[root@master ~]# tar -zxvf mpc-0.8.1.tar.gz
[root@master ~]# cd mpc-0.8.1
[root@master mpc-0.8.1]# ./configure --prefix=/usr/local/mpc -with-mpfr=/usr/local/mpfr -with-gmp=/usr/local/gmp
[root@master mpc-0.8.1]# make &&make install
6、编译gcc-4.6
[root@master ~]# tar -jxf gcc-4.6.1.tar.bz2
[root@master ~]# cd gcc-4.6.1
[root@master gcc-4.6.1]# ./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr/ --with-mpc=/usr/local/mpc/
[root@master gcc-4.6.1]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
[root@master gcc-4.6.1]# make && make install
make[4]: Leaving directory `/root/gcc-4.6.1/x86_64-unknown-Linux-gnu/libgomp'
make[3]: Leaving directory `/root/gcc-4.6.1/x86_64-unknown-linux-gnu/libgomp'
make[2]: Leaving directory `/root/gcc-4.6.1/x86_64-unknown-linux-gnu/libgomp'
make[1]: Leaving directory `/root/gcc-4.6.1'
7、新建软链接
[root@master gcc-4.6.1]# mkdir -p /usr/bin/gcc_backup/
[root@master gcc-4.6.1]# mv /usr/bin/{gcc,g++} /usr/bin/gcc_backup/
[root@master gcc-4.6.1]# ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
[root@master gcc-4.6.1]# ln -s /usr/local/gcc/bin/g++ /usr/bin/g++
8、查看gcc版本
[root@master gcc-4.6.1]# gcc --version
gcc (GCC) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
二、源码编译安装gcc4.8
1、下载gcc-4.8.2.tar.bz2
[root@master ~]# wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2
[root@master ~]# tar -jxvf gcc-4.8.2.tar.bz2
[root@master ~]# cd gcc-4.8.2
2、下载配置依赖库
[root@master gcc-4.8.2]# ./contrib/download_prerequisites
3、编译目录
[root@master gcc-4.8.2]# mkdir gcc-build-4.8.2
[root@master gcc-4.8.2]# cd gcc-build-4.8.2
4、configure
[root@master gcc-build-4.8.2]# ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
configure: creating ./config.status
config.status: creating Makefile
5、make
[root@master gcc-build-4.8.2]# yum install -y glibc-devel.i686 glibc-devel
[root@master gcc-build-4.8.2]# make
true DO=all multi-do # make
make[4]: Leaving directory `/root/gcc-4.8.2/gcc-build-4.8.2/x86_64-unknown-linux-gnu/libatomic'
make[3]: Leaving directory `/root/gcc-4.8.2/gcc-build-4.8.2/x86_64-unknown-linux-gnu/libatomic'
make[2]: Leaving directory `/root/gcc-4.8.2/gcc-build-4.8.2/x86_64-unknown-linux-gnu/libatomic'
make[1]: Leaving directory `/root/gcc-4.8.2/gcc-build-4.8.2'
6、make install
[root@master gcc-build-4.8.2]# make install
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/root/gcc-4.8.2/gcc-build-4.8.2/x86_64-unknown-linux-gnu/libatomic'
make[3]: Leaving directory `/root/gcc-4.8.2/gcc-build-4.8.2/x86_64-unknown-linux-gnu/libatomic'
make[2]: Leaving directory `/root/gcc-4.8.2/gcc-build-4.8.2/x86_64-unknown-linux-gnu/libatomic'
make[1]: Leaving directory `/root/gcc-4.8.2/gcc-build-4.8.2'
7、查看版本
[root@master gcc-build-4.8.2]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
Thread model: posix
gcc version 4.8.2 (GCC)