前提:保证旧版的gcc,g++存在! root用户
1. 下载源码和依赖包源码:新建目录bak
wget http://ftp.gnu.org/gnu/gcc/gcc-4.9.3/gcc-4.9.3.tar.gz
#Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+
wget http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz
wget http://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.gz
wget http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.0.tar.gz
$ ls bak/*.gz
bak/gcc-4.9.3.tar.gz bak/gmp-5.0.1.tar.gz bak/mpc-0.9.tar.gz bak/mpfr-3.1.0.tar.gz
2. 编译
解压tar包,并新建编译目录 t t1 t2 t3,分别进行以上源码编译
$ ls bak
t t1 t2 t3
cd t1 ../gmp-5.0.1/configure --prefix=/usr/local/gmp-5.0.1 make make install cd t2 ../mpfr-3.1.0/configure --prefix=/usr/local/mpfr-3.1.0 --with-gmp=/usr/local/gmp-5.0.1 make make install cd t3 ../mpc-0.9/configure --prefix=/usr/local/mpc-0.9 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0 make make install #设置链接,在/etc/profile文件末尾加上,注意修改后运行#source /etc/profile 使其生效即可 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.9/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-3.1.0/lib cd t ../gcc-4.9.3/configure --prefix=/usr/local/gcc-4.9.3 --with-mpc=/usr/local/mpc-0.9 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0 --disable-multilib --enable-languages=c,c++ --enable-threads=posix --disable-checking make make install