一、升级GCC
1.升级系统GCC版本
(1)下载gcc版本
[root@localhost src]# wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
(2)解压软件包
[root@localhost src]# tar -zxvf gcc-13.2.0.tar.gz
(3)查看解压出来的文件
[root@localhost src]# cd gcc-13.2.0/
[root@localhost gcc-13.2.0]# ls
(4)下载依赖的软件包
[root@localhost gcc-13.2.0]# cd contrib/
[root@localhost contrib]# ls
[root@localhost gcc-13.2.0]# ./contrib/download_prerequisites
(5)创建编译目录
[root@localhost gcc-13.2.0]#mkdir gcc-build-13.2.0
(6)配置
[root@localhost gcc-build-13.2.0]# ../gcc-13.2.0/configure --prefix=/usr/local/gcc --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++,fortran,lto --enable-plugin --enable-initfini-array --disable-libgcj --without-isl --without-cloog --enable-gnu-indirect-function --build=aarch64-linux-gnu --with-stage1-ldflags=' -Wl,-z,relro,-z,now' --with-boot-ldflags=' -Wl,-z,relro,-z,now' --with-multilib-list=lp64
(7)编译
[root@localhost gcc-build-13.2.0]# make -j $(nproc)
(8)安装
[root@localhost gcc-build-13.2.0]# make install
(9)查看系统当前的gcc版本
[root@localhost ~]# gcc –v
使用内建 specs。 COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-linux-gnu/7.3.0/lto-wrapper 目标:aarch64-linux-gnu 配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --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++,fortran,lto --enable-plugin --enable-initfini-array --disable-libgcj --without-isl --without-cloog --enable-gnu-indirect-function --build=aarch64-linux-gnu --with-stage1-ldflags=' -Wl,-z,relro,-z,now' --with-boot-ldflags=' -Wl,-z,relro,-z,now' --with-multilib-list=lp64 线程模型:posix gcc 版本 7.3.0 (GCC) |
(10)设置环境变量
[root@localhost ~]# touch /etc/profile.d/gcc.sh
[root@localhost ~]# echo -e '\nexport PATH=/usr/local/gcc/bin:$PATH\n' >> /etc/profile.d/gcc.sh
(11)刷新环境变量
[root@localhost ~]# source /etc/profile.d/gcc.sh
(12)设置头文件
[root@localhost ~]# ln -sv /usr/local/gcc/include/c++/13.2.0 /usr/include/c++/13.2.0
(13)设置库文件
[root@localhost ~]# touch /etc/ld.so.conf.d/gcc.conf
[root@localhost ~]# echo -e "/usr/local/gcc/lib64" >> /etc/ld.so.conf.d/gcc.conf
(14)查看gcc版本
root@Kylin:~# gcc -v
使用内建 specs。 COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/gcc/libexec/gcc/aarch64-linux-gnu/13.2.0/lto-wrapper 目标:aarch64-linux-gnu 配置为:../gcc-13.2.0/configure --prefix=/usr/local/gcc --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++,fortran,lto --enable-plugin --enable-initfini-array --disable-libgcj --without-isl --without-cloog --enable-gnu-indirect-function --build=aarch64-linux-gnu --with-stage1-ldflags=' -Wl,-z,relro,-z,now' --with-boot-ldflags=' -Wl,-z,relro,-z,now' --with-multilib-list=lp64 线程模型:posix Supported LTO compression algorithms: zlib gcc 版本 13.2.0 (GCC) |
(15)查看g++版本
root@Kylin:~# g++ -v