您的位置:首页 > 房产 > 家装 > 多版本GCC安装及切换

多版本GCC安装及切换

2024/10/5 20:25:02 来源:https://blog.csdn.net/flysnow010/article/details/139774622  浏览:    关键词:多版本GCC安装及切换

目录

  • 1 背景
  • 2 安装
  • 3 配置
  • 4 切换
    • 4.1 切换到版本9
    • 4.2 切换到版本10

1 背景

最近在研究C++20中的协程需要安装GCC版本10。用到GCC多版本切换,记录步骤。

2 安装

运行如下命令安装两个版本编译器:

sudo apt install gcc-9 g++-9
sudo apt install gcc-10 g++-10

3 配置

使用update-alternatives命令配置多编译器版本:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10

说明:

  • gcc与g++版本绑定在一起了,修改gcc版本会同时修改g++版本

4 切换

使用如下命令切换编译器版本:

sudo update-alternatives --config gcc

4.1 切换到版本9

$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-10   100       auto mode1            /usr/bin/gcc-10   100       manual mode2            /usr/bin/gcc-9    90        manual modePress <enter> to keep the current choice[*], or type selection number: 2

查看版本:

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.3) 9.4.0
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.
$ g++ --version
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.3) 9.4.0
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.

4.2 切换到版本10

$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-10   100       auto mode1            /usr/bin/gcc-10   100       manual mode2            /usr/bin/gcc-9    90        manual modePress <enter> to keep the current choice[*], or type selection number: 1

查看版本:

$ gcc --version
gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
Copyright (C) 2020 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.
$ g++ --version
g++ (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
Copyright (C) 2020 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.

版权声明:

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

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