获取GCC 4.8.2包:wget http://gcc.skazkaforyou.com/releases/gcc-4.8.2/gcc-4.8.2.tar.gz
解压缩:tar -xf gcc-4.8.2.tar.gz
安装依赖库 进入到目录gcc-4.8.2 执行./contrib/download_prerequisites
建立编译所需输出目录并到目录里:mkdir gcc-build-4.8.2;cd gcc-build-4.8.2
执行 ../gcc-4.8.2/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
报错:gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0遂安装这三个工具
此三个安装包有安装顺序 下载好相应安装包后:(GMP4.3.2&MPC1.0.1&MPFR3.1.3)
1.先开始安装GMP。解压GMP的压缩包后,得到源代码目录gmp-4.3.2。在该目录的同级目录下建立一个临时的编译目录,这里命名为tempGMP。
进入tempGMP目录,输入以下命令进行配置:
../gmp-4.3.2/configure --prefix=/home/gmp-4.3.2
make -j4
sudo make install
2.再安装mpfr。解压mpfr的压缩包后,得到源代码目录mpfr-3.1.3。在该目录的同级目录下建立一个临时的编译目录,这里命名为tempMPFR。
进入tempMPFR目录,输入以下命令进行配置:
../mpfr-3.1.3/configure --prefix=/home/mpfr-3.1.3 --with-gmp=/home/gmp-4.3.2
make -j4
sudo make install
2.最后安装mpc。解压mpc的压缩包后,得到源代码目录mpc-1.0.1。在该目录的同级目录下建立一个临时的编译目录,这里命名为tempMPC。
进入tempMPC目录,输入以下命令进行配置:
../mpc-1.0.1/configure --prefix=/home/mpc-1.0.1 --with-gmp=/home/gmp-4.3.2 --with-mpfr=/home/mpfr-3.1.3
make -j4
sudo make install
坑1:在三个插件configure时如遇到 "configure: error: could not find a working compiler"
解决:在命令末尾添加"--build=x86_64-linux"(问题系CPU处理器位数所致)
3个插件安装后 开始重新configure GCC4.8
坑2:GCC configure时报错"configure: error: cannot compute suffix of object files: cannot compile....."
解决:vi/etc/profile
添加export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/mpc-1.0.1/lib:/home/gmp-4.3.2/lib:/home/mpfr-3.1.3/lib
之后运行#source /etc/profile(问题系插件安装后未添加到环境变量)
再次configure GCC4.8
../gcc-4.8.2/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
坑3:仍然找不到3个插件,错误提示手动添加插件地址,改用如下命令:
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/home/gmp-4.3.2 --with-mpfr=/home/mpfr-3.1.3 --with-mpc=/home/mpc-1.0.1
configure成功后,进行编译
make -j4
make install
编译成功后 gcc -v查看版本 出现gcc version 4.8.2 (GCC) 字样代表安装成功!