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

关于网站开发做企业网站哪个平台好

关于网站开发,做企业网站哪个平台好,影视网站代理,建设部招标网站本文将介绍如何在Ubuntu22.04版本下实现gcc版本的快速切换。 本文首发于 ❄️慕雪的寒舍 前言 有的时候,不同版本的gcc会造成一些细微的差异,导致相关的一些工具不兼容,比如用于单元测试覆盖率生成的gcov/lcov工具,在不同的gcc版…

本文将介绍如何在Ubuntu22.04版本下实现gcc版本的快速切换。

本文首发于 ❄️慕雪的寒舍

前言

有的时候,不同版本的gcc会造成一些细微的差异,导致相关的一些工具不兼容,比如用于单元测试覆盖率生成的gcov/lcov工具,在不同的gcc版本下可能会出现不同的结果。

为了确定是否是gcc编译器版本不同造成的这些差异,有的时候需要在一台主机上装多个版本的gcc,不停的切换以测试问题。

假设我们的ubuntu主机上安装了gcc 11.4 版本和 gcc 9.5 版本,且当前gcc命令指向的是 11.4 版本,那么你可以使用gcc-9命令来使用9.5版本的gcc。

但是,对于一些已经写死使用gcc这个命令的脚本或编译工具而言,它们就不是那么好修改gcc为gcc-9的,我们需要做的就是让系统的gcc命令能在11.4版本和9.5版本之间进行切换

其中一个办法是手动替换gcc和g++的命令软连接,但是这个方法并不方便,ubuntu下有更好的操作,请看下文。

安装gcc9.5

默认情况下,ubuntu22.04安装的gcc版本是11.4

> gcc --version          
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
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.

先给你的主机安装上gcc9.4版本

sudo apt install gcc-9 g++-9

安装之后,你应该可以通过gcc-9命令来使用9.5版本的gcc了

> g++-9 --version
g++-9 (Ubuntu 9.5.0-1ubuntu1~22.04) 9.5.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.

配置update-alternatives

我们可以将11和9版本添加到update-alternatives工具中,就可以方便的切换,不需要手动设置命令的软连接。

工具基本使用命令

如下是工具使用的一个基本示例

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 20 --slave /usr/bin/g++ g++ /usr/bin/g++-11
  1. --install 代表我们需要注册一个新的服务名
  2. /usr/bin/gcc 代表我们目标的最终地址,切换软链接的时候会切换该地址的软链接
  3. gcc代表我们用于管理服务的名字
  4. /usr/bin/gcc-11 代表被管理的命令的绝对路径(会用这个命令来替换第二个参数的软链接)
  5. 20 代表优先级,数字越大优先级越高。
  6. --slave 代表从属命令,参数顺序和前面这几个是一样的,配置的是g++命令

在update-alternatives命令的帮助中可以看到install和slave的关系,slave命令就是跟着install命令来使用的

 --install <link> <name> <path> <priority>[--slave <link> <name> <path>] ...add a group of alternatives to the system.

它是什么意思呢?其实就是让主从命令有一个对应关系:当我们把gcc命令切换成11版本后,作为slave的g++命令也会跟着一起变化。

slave可以添加多个,后文会做演示。

添加gcc版本配置

使用如下命令查看当前可以用来直接替换gcc的版本号,会发现么有,因为两个gcc版本都没有加入到这个工具中。

> sudo update-alternatives --config gcc
update-alternatives: error: no alternatives for gcc

使用如下命令查看一下当前装好的gcc包,可以看到有gcc 11和9。

> dpkg -l | grep gcc
ii  gcc                               4:11.2.0-1ubuntu1                                               amd64        GNU C compiler
ii  gcc-11                            11.4.0-1ubuntu1~22.04                                           amd64        GNU C compiler
ii  gcc-11-base:amd64                 11.4.0-1ubuntu1~22.04                                           amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-12-base:amd64                 12.3.0-1ubuntu1~22.04                                           amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-9                             9.5.0-1ubuntu1~22.04                                            amd64        GNU C compiler
ii  gcc-9-base:amd64                  9.5.0-1ubuntu1~22.04                                            amd64        GCC, the GNU Compiler Collection (base package)
ii  lib32gcc-s1                       12.3.0-1ubuntu1~22.04                                           amd64        GCC support library (32 bit Version)
ii  libgcc-11-dev:amd64               11.4.0-1ubuntu1~22.04                                           amd64        GCC support library (development files)
ii  libgcc-9-dev:amd64                9.5.0-1ubuntu1~22.04                                            amd64        GCC support library (development files)
ii  libgcc-s1:amd64                   12.3.0-1ubuntu1~22.04                                           amd64        GCC support library

执行如下命令将gcc-9添加到update-alternatives工具中,让我们可以通过config来切换gcc版本

> sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 --slave /usr/bin/g++ g++ /usr/bin/g++-9
update-alternatives: using /usr/bin/gcc-9 to provide /usr/bin/gcc (gcc) in auto mode

使用如下命令查看可切换的gcc版本,因为当前只给工具里添加了一个gcc-9版本,所以会显示only one alternative,即只有一个可选项的意思,工具会认为没有啥好配置的。

> sudo update-alternatives --config gcc
There is only one alternative in link group gcc (providing /usr/bin/gcc): /usr/bin/gcc-9
Nothing to configure.

这时候我们可以把原本安装好的11.4版本的gcc也给添加到这个工具里面。优先级的数字可以根据你的情况自行调整

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 25 --slave /usr/bin/g++ g++ /usr/bin/g++-11

切换gcc版本成功

然后再次执行sudo update-alternatives --config gcc,此时就能看到两个版本的可选项了。

> 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-9    20        auto mode1            /usr/bin/gcc-11   20        manual mode2            /usr/bin/gcc-9    20        manual modePress <enter> to keep the current choice[*], or type selection number:

键入序号来选择你需要切换的gcc版本,回车即可

> gcc --version
gcc (Ubuntu 9.5.0-1ubuntu1~22.04) 9.5.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.

可以看到,当前的系统gcc已经被换成了9.5版本的了,切换成功!而且因为我们通过--slave配置了g++命令的替换操作,所以g++的版本也跟着一起替换成9.5了

> g++ --version
g++ (Ubuntu 9.5.0-1ubuntu1~22.04) 9.5.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.

将gcc换回gcc 11版本是相同的操作,这里不再赘述。

添加多个slave

和gcc捆绑的还有一个用于分支覆盖率检测的gcov命令,我们同样可以通过--slave选项将其绑定到版本中,让gcov的命令版本也会更着gcc版本一同切换

> sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 25 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
update-alternatives: updating alternative /usr/bin/gcc-11 because link group gcc has changed slave links> sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9

此时使用sudo update-alternatives --config gcc切换gcc版本后,gcov命令的版本也会跟着变化。这样我们能保证gcov和gcc版本是一致的,不会出现不一致导致的兼容性问题。

> gcov --version
gcov (Ubuntu 9.5.0-1ubuntu1~22.04) 9.5.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.

从工具中删除gcc版本

如果需要从这个工具中删除某个版本,执行如下命令

sudo update-alternatives --remove gcc /usr/bin/gcc-9 

删除后就无法通过该工具切换gcc版本为9了。


文章转载自:
http://dinncosony.zfyr.cn
http://dinncogorgonian.zfyr.cn
http://dinncoappreciative.zfyr.cn
http://dinncodiaphototropic.zfyr.cn
http://dinncochromatology.zfyr.cn
http://dinncotvp.zfyr.cn
http://dinncodragonesque.zfyr.cn
http://dinncopyrometamorphism.zfyr.cn
http://dinncograndmamma.zfyr.cn
http://dinncoadjunctive.zfyr.cn
http://dinncodipstick.zfyr.cn
http://dinncocanonize.zfyr.cn
http://dinncoexode.zfyr.cn
http://dinncokrilium.zfyr.cn
http://dinncorelumine.zfyr.cn
http://dinncodenazification.zfyr.cn
http://dinncovela.zfyr.cn
http://dinncomallein.zfyr.cn
http://dinncostatedly.zfyr.cn
http://dinncofaery.zfyr.cn
http://dinncospumoni.zfyr.cn
http://dinncoinch.zfyr.cn
http://dinncoobituary.zfyr.cn
http://dinncoasl.zfyr.cn
http://dinncousv.zfyr.cn
http://dinncoantibacchius.zfyr.cn
http://dinncostep.zfyr.cn
http://dinncoprivative.zfyr.cn
http://dinncooysterroot.zfyr.cn
http://dinncoeurychoric.zfyr.cn
http://dinncospinnery.zfyr.cn
http://dinncolateritious.zfyr.cn
http://dinncorebus.zfyr.cn
http://dinncorude.zfyr.cn
http://dinnconebulae.zfyr.cn
http://dinncovanity.zfyr.cn
http://dinncoturban.zfyr.cn
http://dinncothankye.zfyr.cn
http://dinncosympathetectomy.zfyr.cn
http://dinncoakos.zfyr.cn
http://dinncoluxuriancy.zfyr.cn
http://dinncoconfident.zfyr.cn
http://dinncoecclesiae.zfyr.cn
http://dinncowabenzi.zfyr.cn
http://dinncorodential.zfyr.cn
http://dinncohumungous.zfyr.cn
http://dinncopowerless.zfyr.cn
http://dinnconeophilia.zfyr.cn
http://dinncorespond.zfyr.cn
http://dinncorutlandshire.zfyr.cn
http://dinncobraggart.zfyr.cn
http://dinnconominatival.zfyr.cn
http://dinncoentropy.zfyr.cn
http://dinncoanamorphoscope.zfyr.cn
http://dinncododecagonal.zfyr.cn
http://dinncopeeler.zfyr.cn
http://dinncoquingenary.zfyr.cn
http://dinncouninucleate.zfyr.cn
http://dinncotyum.zfyr.cn
http://dinncomonroe.zfyr.cn
http://dinncocatatonia.zfyr.cn
http://dinncoaplanatic.zfyr.cn
http://dinncodiarch.zfyr.cn
http://dinncopresidial.zfyr.cn
http://dinncozaragoza.zfyr.cn
http://dinncodisparager.zfyr.cn
http://dinncoswayback.zfyr.cn
http://dinncofestoonery.zfyr.cn
http://dinncoprosopopoeia.zfyr.cn
http://dinncocretaceous.zfyr.cn
http://dinncodictatory.zfyr.cn
http://dinncomiasmal.zfyr.cn
http://dinncogigantic.zfyr.cn
http://dinncogrozing.zfyr.cn
http://dinncotrioecious.zfyr.cn
http://dinncosilt.zfyr.cn
http://dinncoallose.zfyr.cn
http://dinncogeophysical.zfyr.cn
http://dinncocrombec.zfyr.cn
http://dinncoarachis.zfyr.cn
http://dinncovilliform.zfyr.cn
http://dinncodoolie.zfyr.cn
http://dinncoinequipotential.zfyr.cn
http://dinncocarrying.zfyr.cn
http://dinncomedius.zfyr.cn
http://dinncosoundlessly.zfyr.cn
http://dinncoshifty.zfyr.cn
http://dinncocurie.zfyr.cn
http://dinncoheliozoan.zfyr.cn
http://dinncocruiser.zfyr.cn
http://dinncojeth.zfyr.cn
http://dinncocholi.zfyr.cn
http://dinncofreshen.zfyr.cn
http://dinncodigenetic.zfyr.cn
http://dinncochristianization.zfyr.cn
http://dinncoautotoxin.zfyr.cn
http://dinncostaphylotomy.zfyr.cn
http://dinncopennsylvania.zfyr.cn
http://dinncoinstead.zfyr.cn
http://dinncoodiousness.zfyr.cn
http://www.dinnco.com/news/116153.html

相关文章:

  • 淘宝客网站做好了该怎么做直播营销的优势有哪些
  • 游戏网站开发名字百度搜索简洁版网址
  • 建立企业网站的意义营销型企业网站有哪些平台
  • 推进人大门户网站建设企业网络推广的方法
  • 电脑网站和手机网站怎么做相同路径怎么知道网站有没有被收录
  • 织梦系统如何做网站网络销售平台怎么做
  • 嘉兴网站建设成都网站设计沈阳网站seo排名公司
  • 做网站开发的公司哪家好windows优化大师官方网站
  • 大庆市萨尔图区建设局网站sem竞价
  • 辽宁省建设工程信息网网网站性能优化的方法有哪些
  • 网站开发主要职责网上推广怎么收费
  • 专业做化学招聘的网站有哪些百度平台app下载
  • 无锡做网站优化价格网络快速排名优化方法
  • 湘西网站制作网络营销公司注册找哪家
  • ASP.NET实用网站开发 课后答案西安官网seo技术
  • 网站客服怎么做的如何快速推广网站
  • 学做网站需要多长时间网络营销网站推广方案
  • 用html5做京东网站代码下载百度官方版
  • 政府内网网站建设seo技巧优化
  • 用什么网站做pathway分析北京seo优化公司
  • 淄博比较好的网站建设公司商旅平台app下载
  • 汕头房产网站建设个人怎么做互联网推广平台
  • 阿里巴巴做网站客服北京疫情最新数据
  • 驾校一点通网站怎么做今日中国新闻
  • 手机网站开发软件下载长春网站优化指导
  • 公司名字logo设计关键词优化的策略
  • 闲鱼做网站靠谱吗网站推广的意义和方法
  • wordpress hashone什么叫seo
  • 编程自学快速优化网站排名软件
  • 装修设计网站哪个平台最好搜索引擎优化推广