步骤1:查看当前服务器gcc版本
gcc –version
步骤2:查看当前gcc安装目录
find / -name gcc
cd /usr/bin
ll gcc*
因为gcc,g++,c++都是配套的,查找出 g++和c++的原版本位置
步骤3:安装下载依赖包
yum install glibc-headers gcc-c++ gcc gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel
yum install libffi-devel
./contrib/download_prerequisites
步骤4:安装依赖包
cd /*自己的目录*/gcc-11.4.0/mpfr-3.1.6
./configure --prefix=/usr/local/ mpfr-3.1.6
make
make install
cd /*自己的目录*/gcc-11.4.0/mpc-1.0.3
./configure --prefix=/usr/local/ mpc-1.0.3
make
make install
cd /*自己的目录*/gcc-11.4.0/gmp-6.1.0
./configure --prefix=/usr/local/ gmp-6.1.0
make
make install
cd /*自己的目录*/gcc-11.4.0/isl-0.18
./configure --prefix=/usr/local/ isl-0.18
make
make install
修改环境变量vim ~/.bashrc,添加如下
export LD_LIBRARY_PATH=:$LD_LIBRARY_PATH:/usr/local/mpc-1.0.3/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gmp-6.0.1/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpfr-3.1.6/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/isl-0.18/lib
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/
使环境变量生效 source ~/.bashrc
步骤5:安装gcc
进入目录/*自己的目录*/gcc-11.4.0/,新建build文件夹,进入该文件夹,执行以下命令
../configure --prefix=/usr/local/gcc-11.4.0 --with-gmp=/usr/local/gmp-6.0.1/ --with-mpfr=/usr/local/mpfr-3.1.6/ --with-mpc=/usr/local/mpc-1.0.3/ --with-isl=/usr/local/isl-0.18 --with-system-zlib --disable-multilib
再执行如下命令:
make
make install
成功后如下图所示:
修改环境变量~/.bashrc,添加如下
使环境变量生效 ~/.bashrc
步骤6:更新gcc软连接
cd /usr/bin
更新gcc
mv gcc gcc.bak
ln -s /usr/local/gcc-11.4.0/bin/gcc /usr/bin/gcc
更新g++
mv g++ g++.bak
ln -s /usr/local/gcc-11.4.0/bin/g++ /usr/bin/g++
更新c++
mv c++ c++.bak
ln -s /usr/local/gcc-11.4.0/bin/c++ /usr/bin/c++
更新libstdc++.so.6
cd /usr/lib64/
cp /usr/local/gcc-11.4.0/lib64/libstdc++.so.6.0.29 /usr/lib64/
mv libstdc++.so.6 libstdc++.so.6.bak
ln -s /usr/lib64/libstdc++.so.6.0.29 /usr/lib64/libstdc++.so.6
步骤7:测试新版本gcc
最后:出错解决方式
出错:gcc configure: error: C compiler cannot create executables
解决:查找日志Config.log,在里面搜索error,定位到问题
问题:error while loading shared libraries: libmpc.so.2: cannot open shared object file: No such file or directory
解决:[student2@node01 ~]$ locate libmpc.so.2
/opt/software/mpc-0.8.1/lib/libmpc.so.2
/opt/software/mpc-0.8.1/lib/libmpc.so.2.0.0
将export LD_LIBRARY_PATH=/opt/software/mpc-0.8.1/lib/:$LD_LIBRARY_PATH 添加到环境变量~/.bashrc,执行source ~/.bashrc使环境变量生效
问题:locate: command not found
解决:yum -y install mlocate
问题:locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
解决:updatedb
问题
文章来源:https://www.toymoban.com/news/detail-818418.html
解决:在环境变量中添加export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/文章来源地址https://www.toymoban.com/news/detail-818418.html
到了这里,关于Centos升级gcc版本的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!