1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Centos GCC 版本升级

Centos GCC 版本升级

时间:2023-08-07 02:47:49

相关推荐

Centos GCC 版本升级

Centos GCC 版本升级

在阿里云镜像下的这个目录,不同版本略有差异,一般是在该版本镜像下的sclo/x86_64/rh/ 有红帽封装完成的镜像包。0921我看的时候,现在gcc 最新的版本是centos 7.9的版本。也就是devtoolset-11,gcc版本为11.2.1。

/centos-vault/7.5.1804/sclo/x86_64/rh/

/centos/7.9./sclo/x86_64/rh/Packages/d/

CentOS 7官方源的gcc最新版本是4.8.5,发布于,年代久远且不支持c++14。要编译c++14及以上项目,必须要升级现有版本或者安装高版本的gcc。红帽其实已经编译好了高版本的gcc,但未更新到base和epel这两个常用源中,而是将这些版本放在scl中。解决办法有两种:手动编译(也可以从其他机器拷贝或者网上下载),或从源安装。

我这边是从源进行安装的

[root@Centos7 ~]# hostnamectl Static hostname: Centos7Icon name: computer-vmChassis: vmMachine ID: b7efed295d184dd1be0b2d79a9212bd2Boot ID: 7abb88ee9ea3443aba1fa784dc9aab49Virtualization: vmwareOperating System: CentOS Linux 7 (Core)CPE OS Name: cpe:/o:centos:centos:7Kernel: Linux 3.10.0-862.el7.x86_64Architecture: x86-64[root@Centos7 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@Centos7 ~]# [root@Centos7 ~]# yum install -y centos-release-scl...中间忽略已安装:centos-release-scl.noarch 0:2-3.el7.centos作为依赖被安装:centos-release-scl-rh.noarch 0:2-3.el7.centos完毕![root@Centos7 ~]# yum repolist 已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile* base: * centos-sclo-rh: * centos-sclo-sclo: mirrors.* extras: mirrors.* updates: 源标识 源名称 状态base/7/x86_64 CentOS-7 - Base 10,072centos-sclo-rh/x86_64 CentOS-7 - SCLo rh 8,112centos-sclo-sclo/x86_64 CentOS-7 - SCLo sclo 816extras/7/x86_64CentOS-7 - Extras 516updates/7/x86_64 CentOS-7 - Updates 4,160repolist: 23,676##列出GCC版本[root@Centos7 ~]# yum list |grep devtoolset |grep gcc.x86_64devtoolset-10-gcc.x86_64 10.2.1-11.2.el7 centos-sclo-rhdevtoolset-11-annobin-plugin-gcc.x86_64 10.38-1.el7 centos-sclo-rhdevtoolset-11-gcc.x86_64 11.2.1-9.el7 centos-sclo-rhdevtoolset-7-gcc.x86_647.3.1-5.16.el7 centos-sclo-rhdevtoolset-8-gcc.x86_648.3.1-3.2.el7centos-sclo-rhdevtoolset-9-gcc.x86_649.3.1-2.2.el7centos-sclo-rh[root@Centos7 ~]# yum --disablerepo="*" --enablerepo="centos-sclo-rh" list available |grep gcc.x86_64devtoolset-10-gcc.x86_64 10.2.1-11.2.el7 centos-sclo-rhdevtoolset-11-annobin-plugin-gcc.x86_64 10.38-1.el7 centos-sclo-rhdevtoolset-11-gcc.x86_64 11.2.1-9.el7centos-sclo-rhdevtoolset-7-gcc.x86_647.3.1-5.16.el7 centos-sclo-rhdevtoolset-8-gcc.x86_648.3.1-3.2.el7centos-sclo-rhdevtoolset-9-gcc.x86_649.3.1-2.2.el7centos-sclo-rh

这些软件包可以同时安装,不会相互覆盖和冲突,也不会覆盖系统的版本。即可以在系统中可同时存在gcc 7, gcc 8, gcc 10等多个版本。结果如下

[root@Centos7 ~]# yum -y install devtoolset-10-gcc devtoolset-10-gcc-c++ 已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile* base: * centos-sclo-rh: * centos-sclo-sclo: mirrors.* extras: mirrors.* updates: 软件包 devtoolset-10-gcc-10.2.1-11.2.el7.x86_64 已安装并且是最新版本软件包 devtoolset-10-gcc-c++-10.2.1-11.2.el7.x86_64 已安装并且是最新版本无须任何处理[root@Centos7 ~]# yum install devtoolset-9-gcc devtoolset-9-gcc-c++已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile* base: * centos-sclo-rh: * centos-sclo-sclo: mirrors.* extras: mirrors.* updates: 软件包 devtoolset-9-gcc-9.3.1-2.2.el7.x86_64 已安装并且是最新版本软件包 devtoolset-9-gcc-c++-9.3.1-2.2.el7.x86_64 已安装并且是最新版本无须任何处理

因为不会覆盖系统默认的gcc,使用这些软件的方法有四种:

1.使用绝对路径;

[root@Centos7 ~]# rpm -qa |grep devtoolsetdevtoolset-9-gcc-c++-9.3.1-2.2.el7.x86_64devtoolset-10-gcc-10.2.1-11.2.el7.x86_64devtoolset-9-libstdc++-devel-9.3.1-2.2.el7.x86_64devtoolset-10-runtime-10.1-0.el7.x86_64devtoolset-9-gcc-9.3.1-2.2.el7.x86_64devtoolset-9-binutils-2.32-16.el7.x86_64devtoolset-10-libstdc++-devel-10.2.1-11.2.el7.x86_64devtoolset-10-binutils-2.35-5.el7.4.x86_64devtoolset-10-gcc-c++-10.2.1-11.2.el7.x86_64devtoolset-9-runtime-9.1-0.el7.x86_64[root@Centos7 ~]# #查看安装路径[root@Centos7 ~]# rpm -ql devtoolset-10-gcc-10.2.1-11.2.el7.x86_64/opt/rh/devtoolset-10/root/usr/bin/cc/opt/rh/devtoolset-10/root/usr/bin/cpp/opt/rh/devtoolset-10/root/usr/bin/gcc/opt/rh/devtoolset-10/root/usr/bin/gcc-ar/opt/rh/devtoolset-10/root/usr/bin/gcc-nm/opt/rh/devtoolset-10/root/usr/bin/gcc-ranlib以下输出忽略[root@Centos7 ~]# gcc -v使用内建 specs。COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper目标:x86_64-redhat-linux配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=/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-0702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-0702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux线程模型:posixgcc 版本 4.8.5 0623 (Red Hat 4.8.5-28) (GCC) [root@Centos7 ~]# [root@Centos7 ~]# /opt/rh/devtoolset-10/root/usr/bin/gcc -vUsing built-in specs.COLLECT_GCC=/opt/rh/devtoolset-10/root/usr/bin/gccCOLLECT_LTO_WRAPPER=/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapperTarget: x86_64-redhat-linuxConfigured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-10/root/usr --mandir=/opt/rh/devtoolset-10/root/usr/share/man --infodir=/opt/rh/devtoolset-10/root/usr/share/info --with-bugurl=/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-10.2.1-0130/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linuxThread model: posixSupported LTO compression algorithms: zlibgcc version 10.2.1 0130 (Red Hat 10.2.1-11) (GCC) [root@Centos7 ~]# /opt/rh/devtoolset-9/root/usr/bin/gcc -vUsing built-in specs.COLLECT_GCC=/opt/rh/devtoolset-9/root/usr/bin/gccCOLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapperTarget: x86_64-redhat-linuxConfigured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linuxThread model: posixgcc version 9.3.1 (Red Hat 9.3.1-2) (GCC)

2.添加可执行文件路径到PATH环境变量;

3.使用官方推荐的加载命令:scl enable devtoolset-x bash, x为要启用的版本;

只对当前终端生效

[root@Centos7 ~]# scl enable devtoolset-10 bash [root@Centos7 ~]# gcc -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapperTarget: x86_64-redhat-linuxConfigured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-10/root/usr --mandir=/opt/rh/devtoolset-10/root/usr/share/man --infodir=/opt/rh/devtoolset-10/root/usr/share/info --with-bugurl=/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-10.2.1-0130/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linuxThread model: posixSupported LTO compression algorithms: zlibgcc version 10.2.1 0130 (Red Hat 10.2.1-11) (GCC)

4.执行安装软件自带的脚本:source /opt/rh/devtoolset-x/enable,x为要启用的版本。

[root@Centos7 ~]# [root@Centos7 ~]# source /opt/rh/devtoolset-9/enable [root@Centos7 ~]# gcc -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapperTarget: x86_64-redhat-linuxConfigured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linuxThread model: posixgcc version 9.3.1 (Red Hat 9.3.1-2) (GCC)

实践推荐使用最后两种方式。

如果希望长期使用某个高版本,可将此命令写入.bashrc等配置文件。

其它

scl以及scl-rh源中的软件包都安装在/opt/rh/目录下,包含可执行文件、配置等。启用命令的路径是/opt/rh/xxx/enable,安装的服务重启命令则是systemctl restart rh-xxx,需要加rh或scl前缀以区别其他源的包。如果你用过remi/gitlab等源,其行为方式也是类似的。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。