[Solve Error] Install g++ in Ubuntu20.04 : g++ : Depends: g++-7 (>= 7.4.0-1~)

这是在Windows10上的Ubuntu WSL环境中遇到的问题。
目前的Ubuntu版本是Ubuntu 20.04.1 LTS。并且使用了阿里的apt镜像源。

先说结论,Ubuntu版本之高使得本机使用apt源中没有所需的库版本。所以可以尝试将apt源换回官方源。然后apt update再安装g++。

以下是断案过程。


在使用命令sudo apt install g++遇到了依赖问题。整个依赖链排查结果如下:

sucicada@20200702-143805:/etc/apt/sources.list.d$ sudo apt install g++
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 g++ : Depends: g++-7 (>= 7.4.0-1~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
sucicada@20200702-143805:/etc/apt/sources.list.d$ sudo apt install g++-7
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 g++-7 : Depends: libstdc++-7-dev (= 7.5.0-3ubuntu1~18.04) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
sucicada@20200702-143805:/etc/apt/sources.list.d$ sudo apt install libstdc++-7-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libstdc++-7-dev : Depends: libc6-dev (>= 2.13-0ubuntu6) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
sucicada@20200702-143805:/etc/apt/sources.list.d$ sudo apt install libc6-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libc6-dev : Depends: libc6 (= 2.27-3ubuntu1.3) but 2.31-0ubuntu9.1 is to be installed
             Depends: libc-dev-bin (= 2.27-3ubuntu1.3) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

反正层层找下来问题是这个:

 libc6-dev : Depends: libc6 (= 2.27-3ubuntu1.3) but 2.31-0ubuntu9.1 is to be installed

库中的包版本和系统已安装的不符合。这个包是底层包不能删。

接下来我们使用apt policy libc6-dev libc6来检查下依赖关系。如下

sucicada@20200702-143805:/etc/apt/sources.list.d$ apt policy libc6-dev libc6
libc6-dev:
  Installed: (none)
  Candidate: 2.27-3ubuntu1.3
  Version table:
     2.27-3ubuntu1.3 500
        500 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages
        500 http://mirrors.aliyun.com/ubuntu bionic-proposed/main amd64 Packages
     2.27-3ubuntu1.2 500
        500 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages
     2.27-3ubuntu1 500
        500 http://mirrors.aliyun.com/ubuntu bionic/main amd64 Packages
libc6:
  Installed: 2.31-0ubuntu9.1
  Candidate: 2.31-0ubuntu9.1
  Version table:
 *** 2.31-0ubuntu9.1 100
        100 /var/lib/dpkg/status
     2.27-3ubuntu1.3 500
        500 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages
        500 http://mirrors.aliyun.com/ubuntu bionic-proposed/main amd64 Packages
     2.27-3ubuntu1.2 500
        500 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages
     2.27-3ubuntu1 500
        500 http://mirrors.aliyun.com/ubuntu bionic/main amd64 Packages

(小科普:***代表库已安装,100代表已安装的地方,500可安装的远端源。这里能看到100和500对应有的不同版本)

通过以上信息我们能知道libc6-dev 这个库的安装在apt源中的候选是2.27版本,但是已经安装的libc6是2.31版本。而且因为我使用了阿里镜像源。所以由此可见阿里源中的版本知道2.27。冲突就是这么产生的。

所以既然如此,那么我们就把apt源换回官方源(好在当时sourse.list文件只是rename),然后apt update。再安装就好了。

如下,正确的依赖情况。

sucicada@20200702-143805:~/PROGRAM/GitHub/ghelper-subscriber-cli$ apt policy libc6-dev libc6
libc6-dev:
  Installed: 2.31-0ubuntu9.1
  Candidate: 2.31-0ubuntu9.1
  Version table:
 *** 2.31-0ubuntu9.1 500
        500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     2.31-0ubuntu9 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
libc6:
  Installed: 2.31-0ubuntu9.1
  Candidate: 2.31-0ubuntu9.1
  Version table:
 *** 2.31-0ubuntu9.1 500
        500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     2.31-0ubuntu9 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
        

这就是一个很舒服很正常的依赖信息了,令人赏心悦目。
果然Linux奇妙无穷。

  • 8
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
To solve this problem, we can follow the following steps: 1. Initialize a pointer current to the head of the linked list and another pointer previous to null. 2. Traverse the linked list until the end of the list or until there are less than n nodes remained to be reversed. 3. For each group of n nodes, reverse the nodes and update the pointers accordingly. 4. If there are less than n nodes remaining, reverse them as well. 5. Return the updated head of the linked list. Here is the Python code that implements the above algorithm: ```python class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def reverseLinkedList(head, n): current = head previous = None while current: last_node_of_previous_part = previous last_node_of_sub_list = current i = 0 while current and i < n: next_node = current.next current.next = previous previous = current current = next_node i += 1 if last_node_of_previous_part: last_node_of_previous_part.next = previous else: head = previous last_node_of_sub_list.next = current previous = last_node_of_sub_list return head ``` Here is an example usage of the above function: ```python # create input linked list: A -> B -> C -> D -> E -> F -> G -> H -> I a = ListNode("A") b = ListNode("B") c = ListNode("C") d = ListNode("D") e = ListNode("E") f = ListNode("F") g = ListNode("G") h = ListNode("H") i = ListNode("I") a.next = b b.next = c c.next = d d.next = e e.next = f f.next = g g.next = h h.next = i # reverse the linked list in groups of 3 nodes head = reverseLinkedList(a, 3) # print the updated linked list: A -> D -> C -> B -> G -> F -> E -> I -> H current = head while current: print(current.val, end=" -> ") current = current.next print("None") ``` Output: ``` A -> D -> C -> B -> G -> F -> E -> I -> H -> None ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值