下载4.8.2源码
wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.8.2/gcc-4.8.2.tar.bz2
下载依赖(gmp-4.3.2、mpfr-2.4.2、mpc-0.8.1)
/usr/install/gcc-4.8.2/contrib/download_prerequisities
依次编译安装依赖
cd /usr/install/gcc-4.8.2/contrib/gmp
mkdir build
cd build
../configure --prefix=/usr/local/gcc/gmp-4.3.2
sudo make
sudo make install
cd /usr/install/gcc-4.8.2/contrib/mpfr
mkdir build
cd build
../configure --prefix=/usr/local/gcc/mpfr-2.4.2 --with-gmp=/usr/local/gcc/gmp-4.3.2
sudo make
sudo make install
cd /usr/install/gcc-4.8.2/contrib/mpc
mkdir build
cd build
../configure --prefix=/usr/local/gcc/mpc-0.8.1 --with-mpfr=/usr/local/gcc/mpfr-2.4.2 --with-gmp=/usr/local/gcc/gmp-4.3.2
sudo make
sudo make install
编译安装gcc4.8.2
注意这里需要将lib加入到编译环境中:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gcc/gmp-4.3.2/lib:/usr/local/gcc/mpc-0.8.1/lib:/usr/local/gcc/mpfr-2.4.2/lib
cd /usr/install/gcc-4.8.2
mkdir build
../configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gcc/gmp-4.3.2 --with-mpfr=/usr/local/gcc/mpfr-2.4.2 --with-mpc=/usr/local/gcc/mpc-0.8.1
sudo make
sudo make install
卸载旧版本
yum remove -y gcc gcc-c++
updatedb
链接新版本
cd /usr/bin
ln -s /usr/local/gcc/bin/gcc gcc
ln -s /usr/local/gcc/bin/g++ g++
检查版本
gcc -v
done