centos6.5 源码升级GCC版本

CentOS 6.5 系统自带GCC版本4.4.7 太老 在编译源码的时候经常报错unrecognized command line option "-std=c++11"

升级GCC版本

1 .安装gcc需要先安装依赖包 gmp, mpfr, mpc

安装 gmp

wget http://mirror.hust.edu.cn/gnu/gmp/gmp-6.1.0.tar.xz

tar zxf gmp-6.1.0.tar.xz

cd gmp-6.1.0

./configure --prefix=/usr/local/gmp

#成功会出现configure.status文件

make

make install

安装mpfr

wget http://mirror.hust.edu.cn/gnu/mpfr/mpfr-3.1.4.tar.gz

tar zxf mpfr-3.1.4.tar.gz

cd mpfr-3.1.4

./configure --prefix=/usr/local/mpfx

#成功会出现configure.status文件

make

make install

安装 mpc

wget http://mirror.hust.edu.cn/gnu/mpc/mpc-1.0.3.tar.gz

tar zxf mpc-1.0.3.tar.gz

cd mpc-1.0.3

./configure --prefix=/usr/local/mpc

#成功会出现configure.status文件

make

make install

2 下载安装gcc

wget http://mirror0.babylon.network/gcc/releases/gcc-4.8.5/gcc-4.8.5.tar.gz

tar zxvf gcc-4.8.5.tar.gz

cd gcc-4.8.5

./configure --help #查看帮助命令

./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

make j4/j8 #编译时间较长 -jn n代表cpu数 加快编译速度

make install

升级gcc动态链接库,把gcc-build-6.1.0/stage1-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.22拷贝到/usr/lib64/文件夹下,首先删除原来软连接:

rm -rf libstdc++.so.6

然后新建软连接,指向libstdc++.so.6.0.22:

ln -s libstdc++.so.6.0.22 libstdc++.so.6

运行 gcc -v 查看版本

如果还是老版本:4.4.7

mv /usr/bin/gcc /usr/bin/gcc447

mv /usr/bin/g++ /usr/bin/g++447

ln -s  /usr/local/gcc/bin/gcc  /usr/bin

ln -s  /usr/local/gcc/bin/g++  /usr/bin

gcc -v

参考文档:https://baijiahao.baidu.com/s?id=1618088009618054622&wfr=spider&for=pc

猜你喜欢

转载自blog.csdn.net/weixin_40902527/article/details/86701363