一、问题描述
某次升级内核,执行make menuconfig报当前版本太低,现场版本为4.8.5,需要升级到5.1.0版本以上,查看官网后,决定升级到5.20版本。注:GCC依赖于gmp 4.2+, mpfr 2.4+和mpc 0.8+,报错如下:
***
*** C compiler is too old.
*** Your GCC version: 4.8.5
*** Minimum GCC version: 5.1.0
***
scripts/Kconfig.include:44: Sorry, this C compiler is not supported.
make[2]: *** [menuconfig] Error 1
make[1]: *** [menuconfig] Error 2
make: *** [__sub-make] Error 2
官方说明:https://gcc.gnu.org/install/index.html;https://gcc.gnu.org/;https://ftp.gnu.org/gnu/gcc/gcc-5.2.0/
二、升级处理
#升级前资源下载
cd /usr/local/src
wget http://ftp.gnu.org/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.bz2 //或如下:2015-07-16
wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.gz
tar -jxvf gcc-5.2.0.tar.bz2
cd gcc-5.2.0
#依赖获取及升级
#查看/contrib/download_prerequisites
#! /bin/sh
GRAPHITE_LOOP_OPT=yes
# Necessary to build GCC.
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1
#wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1
wget https://ftp.gnu.org/gnu/mpfr/$MPFR.tar.bz2 --no-check-certificate || exit 1
tar xjf $MPFR.tar.bz2 || exit 1
ln -sf $MPFR mpfr || exit 1
#wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1
wget https://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 --no-check-certificate || exit 1
tar xjf $GMP.tar.bz2 || exit 1
ln -sf $GMP gmp || exit 1
#wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz || exit 1
wget https://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz --no-check-certificate || exit 1
tar xzf $MPC.tar.gz || exit 1
ln -sf $MPC mpc || exit 1
# Necessary to build GCC with the Graphite loop optimizations.
if [ "$GRAPHITE_LOOP_OPT" = "yes" ] ; then
ISL=isl-0.14
#wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL.tar.bz2 || exit 1
wget https://gcc.gnu.org/pub/gcc/infrastructure/$ISL.tar.bz2 --no-check-certificate || exit 1
tar xjf $ISL.tar.bz2 || exit 1
ln -sf $ISL isl || exit 1
fi
#执行如下,下载依赖包
/contrib/download_prerequisites
#编译安装
mkdir build //创建bulid文件夹
cd build
../gcc-5.2.0/configure --prefix=/usr/local/sharelib/gcc_5.2.0 --enable-languages=c,c++ --enable-threads=posix --disable-multilib --with-system-zlib --enable-checking=release
# 编译安装,此过程耗时较长
make $(nproc --all)
make install
# 修改软连接
mv /usr/bin/gcc /usr/bin/gcc_bak
ln -s /usr/local/sharelib/gcc_5.2.0/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++_bak
ln -s /usr/local/sharelib/gcc_5.2.0/bin/g++ /usr/bin/g++
# 验证
gcc --verson
g++ --version //输出如下
gcc (GCC) 5.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
cc -v //输出如下
Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/usr/local/sharelib/gcc_5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-5.2.0/configure --prefix=/usr/local/sharelib/gcc_5.2.0 --enable-languages=c,c++,go --enable-threads=posix --disable-multilib
Thread model: posix
gcc version 5.2.0 (GCC)