1. gcc源码下载
ftp://gcc.gnu.org/pub/gcc/releases/
[yhwang@yhwang ~] wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.gz
[yhwang@yhwang ~] tar zxvf gcc-8.2.0.tar.gz
下载你所需要的GCC版本。
2. 下载gcc依赖库源码
gmp ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
mpc ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
mpfr ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
[yhwang@yhwang ~] wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
[yhwang@yhwang ~] tar jxvf gmp-6.1.0.tar.bz2
[yhwang@yhwang ~] tar zxvf mpc-1.0.3.tar.gz
[yhwang@yhwang ~] tar jxvf mpfr-3.1.4.tar.bz2
[yhwang@yhwang ~] cd ~/gmp-6.1.0
[yhwang@yhwang ~] ./configure --prefix=/usr/local/gmp
[yhwang@yhwang ~] make && make install
[yhwang@yhwang ~] cd ~/mpc-1.0.3
[yhwang@yhwang ~] ./configure --prefix=/usr/local/mpc
[yhwang@yhwang ~] make && make install
[yhwang@yhwang ~] cd ~/mpfr-3.1.4
[yhwang@yhwang ~] ./configure --prefix=/usr/local/mpfr
[yhwang@yhwang ~] make && make install
[yhwang@yhwang ~] export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
[yhwang@yhwang ~] cd ~/gcc-8.2.0
[yhwang@yhwang ~] ./configure --prefix=/usr/local/gcc --with-gmp=/usr/local/gmp/ --with-mpfr=/usr/local/mpfr/ --with-mpc=/usr/local/mpc/ --with-system-zlib --disable-multilib
[yhwang@yhwang ~] make && make install
3. 注意点
make时遇到:
checking for suffix of object files... configure: error: in `/home/yhwang/gcc-8.2/gcc-8.2.0/x86_64-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[2]: *** [configure-stage1-target-libgcc] 错误 1
make[2]:正在离开目录 `/home/yhwang/gcc-8.2/gcc-8.2.0'
make[1]: *** [stage1-bubble] 错误 2
make[1]:正在离开目录 `/home/yhwang/gcc-8.2/gcc-8.2.0'
make: *** [all] 错误 2
然后就停下了,在编译之前需要输入如下语句
[yhwang@yhwang ~] export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
然后
[yhwang@yhwang ~] make && make install
4. 检查gcc版本
[yhwang@yhwang ~] gcc -v
[yhwang@yhwang ~] g++ -v