下载gcc源码包以及依赖包:
wget https://mirrors.aliyun.com/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
安装gcc/gcc-c++/bzip2工具包
yum install gcc gcc-c++ bzip2
解压gcc源码包到/usr/local/src/
tar zxvf gcc-9.2.0.tar.gz -C /usr/local/src/
将依赖包放到gcc源码包中:
mv 依赖包名 /usr/local/src/gcc-9.2.0
执行先决条件检查:
[root@localhost gcc-9.2.0]# ./contrib/download_prerequisites
gmp-6.1.0.tar.bz2: 确定
mpfr-3.1.4.tar.bz2: 确定
mpc-1.0.3.tar.gz: 确定
isl-0.18.tar.bz2: 确定
All prerequisites downloaded successfully.
源码包配置:
./configure \
--prefix=/usr/local/gcc \
--enable-bootstrap \
--enable-checking=release \
--enable-languages=c,c++ \
--disable-multilib
源码包编译安装:
make -j 20 && make install
安装后配置gcc并查看版本:
# 环境变量
echo "export PATH=/usr/local/gcc/bin:$PATH" >> /etc/profile.d/gcc.sh
# 生效
source /etc/profile.d/gcc.sh
# 头文件
ln -sv /usr/local/gcc/include/ /usr/include/gcc
# 库文件
echo "/usr/local/gcc/lib64" >> /etc/ld.so.conf.d/gcc.conf
# 生效
ldconfig -v
ldconfig -p | grep gcc
# 查看版本:
gcc --version
网友评论