当前位置: 首页 > news >正文

多版本GCC安装及切换

目录

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

1 背景

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

2 安装

2.1 Ubuntu 20.04

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

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

2.2 Ubuntu 18.04

默认安装最高版本gcc-7,添加Toolchain Test Builds PPA(个人软件包存档),它提供了GCC 10的最新版本

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
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.
http://www.lryc.cn/news/383941.html

相关文章:

  • Redis进阶 - 朝生暮死之Redis过期策略
  • MySQL实训--原神数据库
  • Retrieval-Augmented Generation for Large Language Models A Survey
  • 【曦灵平台】深度体验百度智能云曦灵平台之数字人3.0、声音克隆、直播等功能,AI加持就是不一样,快来一起体验
  • 如何使用GPT?初学者的指南
  • 24年了 直播带货的未来如何?
  • 【神经网络】深入理解多层神经网络(深度神经网络
  • CAS原理与JUC原子类
  • 【杂记-浅谈OSPF协议之RouterDeadInterval死区间隔】
  • 【每日刷题】Day75
  • 文件管理器加载缓慢-禁用文件类型自动发现功能
  • .[nicetomeetyou@onionmail.org].faust深入剖析勒索病毒及防范策略
  • Ardupilot开源代码之ExpressLRS性能实测方法
  • Transformers是SSMs:通过结构化状态空间对偶性的广义模型和高效算法(二)
  • Segment any Text:优质文本分割是高质量RAG的必由之路
  • IDEA 学习之 编译内存问题
  • 如何将本地项目推送到gitee仓库
  • 产品经理基础入门
  • 五子棋纯python手写,需要的拿去
  • C# Winform按钮避免重复点击以及解决WinForm中设置Enabled=False为什么还会响应Click事件
  • 谷歌SEO是什么意思?
  • IPFoxy Tips:匿名海外代理IP的使用方法及注意事项
  • 【MySQL进阶之路 | 小结篇】MySQL键约束KEY与索引INDEX
  • 【中学教资科目二】02中学课程
  • Stable Diffusion 亲测这几个SDXL大模型,真的非常好用!
  • DLS策略洞察:如何应对AI数据中心网络交换机市场的爆发式增长?
  • 数据仓库架构设计
  • EasyExcel动态表头多sheet录入,单元格操作样式,自动修改单元格格式
  • Linux的设备模型
  • 初始化一个Android项目时,Android Studio会自动生成一些文件和目录结构,以帮助你快速上手开发