//下载最新的gcc版本可登陆[查看现有的gcc版本](http://ftp.gnu.org/gnu/gcc)
[root@localhost ~]# wget http://ftp.gnu.org/gnu/gcc/gcc-6.1.0/gcc-6.1.0.tar.gz
//解压(若下载的时 .bz2 版时,解压出错时可能没有装解压zip软件,安装方法是 yum install zip2)
[root@localhost ~]# tar -zxvf gcc-6.1.0.tar.gz
[root@localhost ~]# cd gcc-6.1.0
//下载编译需要的依赖项
[root@localhost ~]# ./contrib/download_prerequisites
[root@localhost contrib]# cd ..
[root@localhost ~]#mkdir build_gcc-6.1.0
[root@localhost ~]# cd build_gcc-6.1.0
//生成Makefile文件
[root@localhost build_gcc-6.1.0]# ../gcc-6.1.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
//编译(-j4选项是make对多核处理器的优化,有时候会出错,若出错了直接用 make )
[root@localhost build_gcc-6.1.0]# make -j4
//安装,需要root权限
[root@localhost build_gcc-6.1.0]# make install
//重启查看版本
[root@localhost build_gcc-6.1.0]#shutdown -r now
[root@localhost ~]#gcc -v
//测试
[root@localhost ~]#vim test.cpp
[root@localhost ~]#g++ -std=c++11 -o test test.cpp
//替换老版本的动态库
[root@localhost ~]#find / -name "libstdc++.so*"
[root@localhost ~]#cd /usr/lib64
//不同版本名字会不一样
[root@localhost ~]#cp /root/build_gcc_6.1.0/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.22 ./
//删除原来的软连接
[root@localhost ~]#rm -rf libstdc++.so.6
//建立连接新的动态库的软连接
[root@localhost ~]# ln -s libstdc++.so.6.0.22 libstdc++.so.6
//检查动态库是否有 GLIBCXX_3.4.22输出
[root@localhost ~]#strings /usr/lib64/libstdc++.so.6|grep GLIBC
//大功完成
centos 升级gcc
最新推荐文章于 2025-03-16 21:07:53 发布