您的位置:首页 > 新闻 > 会展 > 站长工具永久_郑州市人民政府网站_百度推广下载_新媒体营销案例

站长工具永久_郑州市人民政府网站_百度推广下载_新媒体营销案例

2025/4/19 6:11:45 来源:https://blog.csdn.net/qq_50247813/article/details/147153079  浏览:    关键词:站长工具永久_郑州市人民政府网站_百度推广下载_新媒体营销案例
站长工具永久_郑州市人民政府网站_百度推广下载_新媒体营销案例

本片文章介绍如何升级gcc,centos7.9 仓库默认的gcc版本为:4.8.5

4.8.5-44) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. ```

一、通过SCL仓库安装

  1. 安装SCL仓库

    由于centos7的scl仓库源已经不在维护了 centos-release-scl,所以我们使用阿里云的scl镜像源

    cat > /etc/yum.repos.d/CentOS-SCLo-scl.repo << EOF
    [centos-sclo-rh]
    name=CentOS-7 - SCLo rh
    baseurl=https://mirrors.aliyun.com/centos-vault/centos/7/sclo/x86_64/rh/
    enabled=1
    gpgcheck=0
    EOF
    
  2. 选择你要安装的gcc版本

    阿里云的scl镜像仓库目前gcc的最高版本为gcc11

    查看所有gcc版本

    [root@192 ~]# yum list | grep devtoolset-
    ......
    devtoolset-11.x86_64                       11.1-2.el7             centos-sclo-rh
    devtoolset-11-annobin-annocheck.x86_64     10.38-1.el7            centos-sclo-rh
    devtoolset-11-annobin-docs.noarch          10.38-1.el7            centos-sclo-rh
    devtoolset-11-annobin-plugin-gcc.x86_64    10.38-1.el7            centos-sclo-rh
    devtoolset-11-binutils.x86_64              2.36.1-1.el7.2         centos-sclo-rh
    devtoolset-11-binutils-devel.x86_64        2.36.1-1.el7.2         centos-sclo-rh
    devtoolset-11-build.x86_64                 11.1-2.el7             centos-sclo-rh
    devtoolset-11-dwz.x86_64                   0.14-2.el7             centos-sclo-rh
    devtoolset-11-dyninst.x86_64               11.0.0-1.el7           centos-sclo-rh
    devtoolset-11-dyninst-devel.x86_64         11.0.0-1.el7           centos-sclo-rh
    devtoolset-11-dyninst-doc.x86_64           11.0.0-1.el7           centos-sclo-rh
    devtoolset-11-dyninst-static.x86_64        11.0.0-1.el7           centos-sclo-rh
    devtoolset-11-dyninst-testsuite.x86_64     11.0.0-1.el7           centos-sclo-rh
    devtoolset-11-elfutils.x86_64              0.185-2.el7            centos-sclo-rh
    devtoolset-11-elfutils-debuginfod.x86_64   0.185-2.el7            centos-sclo-rh
    devtoolset-11-elfutils-debuginfod-client.x86_64
    devtoolset-11-elfutils-debuginfod-client-devel.x86_64
    devtoolset-11-elfutils-devel.x86_64        0.185-2.el7            centos-sclo-rh
    devtoolset-11-elfutils-libelf.x86_64       0.185-2.el7            centos-sclo-rh
    devtoolset-11-elfutils-libelf-devel.x86_64 0.185-2.el7            centos-sclo-rh
    devtoolset-11-elfutils-libs.x86_64         0.185-2.el7            centos-sclo-rh
    devtoolset-11-gcc.x86_64                   11.2.1-9.1.el7         centos-sclo-rh
    devtoolset-11-gcc-c++.x86_64               11.2.1-9.1.el7         centos-sclo-rh
    devtoolset-11-gcc-gdb-plugin.x86_64        11.2.1-9.1.el7         centos-sclo-rh
    devtoolset-11-gcc-gfortran.x86_64          11.2.1-9.1.el7         centos-sclo-rh
    devtoolset-11-gcc-plugin-devel.x86_64      11.2.1-9.1.el7         centos-sclo-rh
    devtoolset-11-gdb.x86_64                   10.2-6.el7             centos-sclo-rh
    devtoolset-11-gdb-doc.noarch               10.2-6.el7             centos-sclo-rh
    devtoolset-11-gdb-gdbserver.x86_64         10.2-6.el7             centos-sclo-rh
    devtoolset-11-libasan-devel.x86_64         11.2.1-9.1.el7         centos-sclo-rh
    devtoolset-11-libatomic-devel.x86_64       11.2.1-9.1.el7         centos-sclo-rh
    devtoolset-11-libgccjit.x86_64             11.2.1-9.1
    ......
    

    安装gcc11

    [root@192 ~]# yum -y install devtoolset-11
    
  3. 激活 gcc 11 环境

    scl enable devtoolset-11 bash 或者 source /opt/rh/devtoolset-11/enable 激活gcc11环境

    [root@192 ~]# scl enable devtoolset-11 bash
    [root@192 ~]# gcc --version
    gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
    Copyright (C) 2021 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    每安装一个gcc版本就会在/opt/rh多一个对应版本的文件,如下

    [root@192 ~]# ls -l /opt/rh
    total 0
    dr-xr-xr-x 3 root root 32 Apr 11 08:46 devtoolset-11
    dr-xr-xr-x 3 root root 32 Apr 11 08:58 devtoolset-9
    

    想要切换到那个版本就执行一下对应目录文件下的enable脚本文件或者 scl enable devtoolset-xx bash 即可

    [root@192 ~]# scl enable devtoolset-9 bash
    [root@192 ~]# gcc --version
    gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
    Copyright (C) 2019 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.[root@192 ~]# source /opt/rh/devtoolset-11/enable
    [root@192 ~]# gcc --version
    gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
    Copyright (C) 2021 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
  4. 永久切换
    每次激活安装的gcc时,只不过是在新的bash或者当前bash中追加了gcc环境,并且有新的根文件,可以从enable文件中体现出来。

    [root@192 ~]# cat /opt/rh/devtoolset-11/enable
    # General environment variables
    export PATH=/opt/rh/devtoolset-11/root/usr/bin${PATH:+:${PATH}}
    export MANPATH=/opt/rh/devtoolset-11/root/usr/share/man${MANPATH:+:${MANPATH}}
    export INFOPATH=/opt/rh/devtoolset-11/root/usr/share/info${INFOPATH:+:${INFOPATH}}
    export PCP_DIR=/opt/rh/devtoolset-11/root
    # bz847911 workaround:
    # we need to evaluate rpm's installed run-time % { _libdir }, not rpmbuild time
    # or else /etc/ld.so.conf.d files?
    rpmlibdir=$(rpm --eval "%{_libdir}")
    # bz1017604: On 64-bit hosts, we should include also the 32-bit library path.
    # bz1873882: On 32-bit hosts, we should include also the 64-bit library path.
    # bz2027377: Avoid unbound variables
    if [ "$rpmlibdir" != "${rpmlibdir/lib64/}" ]; thenrpmlibdir32=":/opt/rh/devtoolset-11/root${rpmlibdir/lib64/lib}"dynpath32="$rpmlibdir32/dyninst"rpmlibdir64=dynpath64=
    elserpmlibdir64=":/opt/rh/devtoolset-11/root${rpmlibdir/lib/lib64}"dynpath64="$rpmlibdir64/dyninst"rpmlibdir32=dynpath32=
    fi
    # Add SCL dyninst to LD_LIBRARY_PATH, both 64- and 32-bit paths.
    export LD_LIBRARY_PATH=/opt/rh/devtoolset-11/root$rpmlibdir/dyninst$dynpath64$dynpath32${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    # Now prepend the usual /opt/.../usr/lib{64,}.
    export LD_LIBRARY_PATH=/opt/rh/devtoolset-11/root$rpmlibdir$rpmlibdir64$rpmlibdir32${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    export PKG_CONFIG_PATH=/opt/rh/devtoolset-11/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
    

    /opt/rh/devtoolset-11/目录下存在一个root目录,gcc二进制文件在就/opt/rh/devtoolset-11/root/bin/ 目录下面

    [root@192 ~]# ls -l /opt/rh/devtoolset-11/
    total 4
    -rwxr-xr-x  1 root root 1456 May 30  2022 enable
    dr-xr-xr-x 17 root root  224 Apr 11 08:46 root
    [root@192 root]# /opt/rh/devtoolset-11/root/bin/gcc --version
    gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
    Copyright (C) 2021 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.[root@192 root]# /opt/rh/devtoolset-11/root/bin/g++ --version
    g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
    Copyright (C) 2021 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    了解到了是如何切换到gcc11就能知道如何永久切换到gcc11
    方法一、 将 scl enable devtoolset-11 bash 或者 source /opt/rh/devtoolset-11/enable 添加到环境变量

    echo "scl enable devtoolset-11 bash" >> /etc/profile
    

    方法二、将devtoolset-11下的gcc 和 g++ 文件链接到 /opt/rh/devtoolset-11/root/bin/gcc/opt/rh/devtoolset-11/root/bin/g++

    mv /usr/bin/gcc /usr/bin/gcc-4.8.5
    mv /usr/bin/g++ /usr/bin/g++-4.8.5
    ln -s /opt/rh/devtoolset-11/root/bin/gcc /usr/bin/gcc
    ln -s /opt/rh/devtoolset-11/root/bin/g++ /usr/bin/g++
    gcc --version
    g++ --version
    

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com