【Linux operation 35】SUSE12SP5 升级gcc为12.1.0

1、环境

系统:SUSE 12SP5 X86_64
gcc版本:4.8

2、下载最新的源码包并解压缩

地址:http://ftp.gnu.org/gnu/gcc/

wget http://ftp.gnu.org/gnu/gcc/gcc-12.1.0/gcc-12.1.0.tar.gz
tar -zxvf gcc-12.1.0.tar.gz

在这里插入图片描述

3.下载依赖及配置文件

zypper -y install bzip2 #SUSE系统已安装可以跳过这一步,可做检查

cd gcc-11.2.0
./contrib/download_prerequisites

4、配置

mkdir build

cd build/

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

#–enable-languages表示你要让你的gcc支持那些语言,
#–disable-multilib不生成编译为其他平台可执行代码的交叉编译器。
#–disable-checking生成的编译器在编译过程中不做额外检查,
#也可以使用*–enable-checking=xxx*来增加一些检查

5. 编译

make

#这一步需要时间非常久 可以使用 make -j 4 让make最多运行四个编译命令同时运行,加快编译速度(建议不要超过CPU核心数量的2倍)
#这一步用了2个小时

6. 安装

make install

7、 验证gcc版本

linux-1psk:/ # gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/12.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.1.0 (GCC) 

验证:gcc -v;或者g++ -v,如果显示的gcc版本仍是以前的版本,就需要重启系统;
或者可以查看gcc的安装位置:which gcc;
然后在查看版本 /usr/local/bin/gcc -v
确定以及配置成功后可以将原先的版本删除

8、删除旧版本

linux-1psk:/ # zypper  remove gcc g++
Loading repository data...
Warning: No repositories defined. Operating only with the installed resolvables. Nothing can be installed.
Reading installed packages...
'g++' not found in package names. Trying capabilities.
No provider of 'g++' found.
Resolving package dependencies...

The following 2 packages are going to be REMOVED:
  gcc gcc-c++

2 packages to remove.
No additional space will be used or freed after the operation.
Continue? [y/n/...? shows all options] (y): y
(1/2) Removing gcc-c++-4.8-6.189.x86_64 ................................................................................................................................................................................[done]
(2/2) Removing gcc-4.8-6.189.x86_64 ....................................................................................................................................................................................[done]

9、配置新版本全局可用


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

猜你喜欢

转载自blog.csdn.net/qq_22938603/article/details/125446874