tar -zxvf gcc-8.4.0.tar.gz
- 下载依赖
yum -y install bzip2 zlib zlib-devel
yum -y install gcc gcc-c++ gdb
将文件 ./contrib/download_prerequisites 中的地址:
ftp://gcc.gnu.org/pub/gcc/infrastructure/
替换为:
http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/
然后执行下载依赖:
cd gcc-8.4.0
chmod +x /opt/gcc-8.4.0/contrib/download_prerequisites
./contrib/download_prerequisites
- 新建编译目录
mkdir build
cd build
- 配置参数
/opt/gcc-8.4.0/configure --prefix=/usr/local/gcc-8.4.0 --enable-threads=posix --disable-checking --disable-multilib --enable--long-long --with-system-zlib --enable-languages=c,c++
- 编译安装
make -j8
make install
- 配置默认为 gcc-8.4.0
ln -snf /usr/local/gcc-8.4.0/bin/gcc /usr/bin/gcc
ln -snf /usr/local/gcc-8.4.0/bin/g++ /usr/bin/g++
- 查看版本
gcc --version
g++ --version