1. 下载软件,解压,并进入软件目录
gcc 7.3下载地址:https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
cd /data && wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
tar -xvf gcc-7.3.0.tar.gz
cd gcc-7.3.0/
2. 编译安装(升级)GCC
2.1 配置
./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-bootstrap
这一步可能会有很多问题,以下是我遇到了三个问题,并给出了解决方案:
问题1:配置报错"configure: error: no acceptable C compiler found in $PATH"
解决方案:执行 yum -y reinstall gcc gcc-c++
问题2:configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
这是缺少依赖库:GMP、MPFR、MPC
解决方案:安装依赖库
yum install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel -y
问题3:I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.
说是32位的开发库文件和头文件可能不存在(其实我也不知道有没有,我装的是64位的,应该是没有的)
解决方案:添加参数--disable-multilib
2.2 编译安装
make -j 8 && make -j8 install
安装时间很长很长~ 40分钟左右,可以干别的事情去了哈
3. 验证gcc版本
gcc -v