CentOS 7 升级 gcc-4.8.5 到 gcc-5.4.0

1、环境介绍

[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# uname -r
3.10.0-957.el7.x86_64

2、下载gcc-5.4.0源码包

[root@localhost ~]# wget http://mirrors.nju.edu.cn/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.gz
[root@localhost ~]# tar xf gcc-5.4.0.tar.gz
[root@localhost ~]# cd gcc-5.4.0/
[root@localhost gcc-5.4.0]# ./contrib/download_prerequisites
"./contrib/download_prerequisites会下载mpfr-2.4.2.tar.bz2 gmp-4.3.2.tar.bz2 mpc-0.8.1.tar.gz isl-0.14.tar.bz2这四个文件"
"下方的tar包里面已经创建好了gcc-build-5.4.0,执行./contrib/download_prerequisites所下载的依赖包也都下载好了,解压后,可以直接开始编译,包的大小为132.97MB"
"链接:https://pan.baidu.com/s/1bEQNC20SLQ3-psEirAzfVg"
"提取码:bfwg"

3、编译安装gcc

[root@localhost gcc-5.4.0]# mkdir gcc-build-5.4.0
[root@localhost gcc-5.4.0]# cd gcc-build-5.4.0/
[root@localhost gcc-build-5.4.0]# ../configure --enable-checking=release \
--enable-languages=c,c++ \
--with-arch_32=x86-64 \
--build=x86_64-redhat-linux \
--disable-multilib
[root@localhost gcc-build-5.4.0]# make && make install
"make && make install执行了大约1小时,可以喝喝茶,看看手机,站起来转两圈"

4、验证gcc版本

[root@localhost ~]# /usr/local/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-redhat-linux/5.4.0/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-checking=release --enable-languages=c,c++ --with-arch_32=x86-64 --build=x86_64-redhat-linux --disable-multilib
Thread model: posix
gcc version 5.4.0 (GCC)
"编译的gcc在/usr/local/bin目录下,/usr/bin/gcc的版本依旧还是4.8.5的"

5、更新gcc连接

"保留一下4.8.5的gcc,后续需要回退的时候,可以方便很多"
[root@localhost ~]# mv /usr/bin/gcc{,-4.8.5}
[root@localhost ~]# mv /usr/lib64/libstdc++.so.6{,-4.8.5}
[root@localhost ~]# mv /usr/bin/g++{,-4.8.5}
[root@localhost ~]# ln -s /usr/local/bin/gcc /usr/bin/gcc
[root@localhost ~]# ln -s /usr/local/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6
[root@localhost ~]# ln -s /usr/local/bin/g++ /usr/bin/g++
"这个时候gcc -v就可以看到gcc的版本变成5.4了"
[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-redhat-linux/5.4.0/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-checking=release --enable-languages=c,c++ --with-arch_32=x86-64 --build=x86_64-redhat-linux --disable-multilib
Thread model: posix
gcc version 5.4.0 (GCC)

猜你喜欢

转载自blog.csdn.net/u010383467/article/details/112644548