一、下载gcc压缩包
# 以gcc4.8.2为例
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.8.2/gcc-4.8.2.tar.gz
# 解压
tar -xvf gcc-4.8.2.tar.gz
二、编译安装
cd gcc-4.8.5/
./contrib/download_prerequisites
mkdir build
cd build
../configure --prefix=/usr/local/gcc4.8.5 --enable-checking=release --enable-languages=c,c++ --disable-multilib
make -j4
make install
三、问题
make -j4
期间可能会报错:
cfns.gperf:101:1: error: 'const char* libc_name_p(const char*, unsigned int)' redeclared inline with 'gnu_inline' attribute
原因是此时是用高版本的gcc去编译低版本gcc,解决方案
四、gcc版本切换
查看当前gcc
版本
gcc --version
gcc (GCC) 8.4.0
Copyright (C) 2018 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.
搜索gcc
文件,会发现此时有多个版本的gcc,例如
find / -name gcc
/usr/local/bin/gcc
/usr/local/gcc4.8.5/bin/gcc
通过sudo删除旧版本软连接
rm /usr/bin/gcc
建立新版本软连接
sudo ln -s /usr/local/gcc4.8.5/bin/gcc /usr/bin/gcc