升级到 17.04 后无法安装 build-essential/gcc/g++

升级到 17.04 后无法安装 build-essential/gcc/g++

自从从 Ubuntu 16.04 升级到 17.04 后,我无法再安装gcc-7g++-7http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu存储库。事实上,我甚至无法安装build-essential

在下面软件与更新>其他软件,存储库列出如下:

http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu zesty main

尝试安装build-essential

$ sudo apt install build-essential
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:
 build-essential : Depends: gcc (>= 4:5.2) but it is not going to be installed
                   Depends: g++ (>= 4:5.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

然而:

$ gcc --version
gcc (Ubuntu 5.4.1-8ubuntu1) 5.4.1 20170304
...
$ g++ --version
g++ (Ubuntu 5.4.1-8ubuntu1) 5.4.1 20170304
...

那么我该如何build-essential再次安装?

答案1

因此我可以build-essential按照以下步骤再次安装:

$ sudo apt install build-essential
...
The following packages have unmet dependencies:
 build-essential : Depends: gcc (>= 4:5.2) but it is not going to be installed
                   Depends: g++ (>= 4:5.2) but it is not going to be installed

gcc需要 5.2 以上的版本,因此让我们尝试安装gcc

$ sudo apt install gcc
...
The following packages have unmet dependencies:
gcc : Depends: cpp (>= 4:6.3.0-2ubuntu1) but it is not going to be installed
      Depends: gcc-6 (>= 6.3.0-9~) but it is not going to be installed

好的。还缺少其他内容。让我们尝试安装它。

$ sudo apt install cpp
...
The following packages have unmet dependencies:
 cpp : Depends: cpp-6 (>= 6.3.0-9~) but it is not going to be installed

仍然没有结果。再试一次。

$ sudo apt install cpp-6
...
The following packages have unmet dependencies:
 cpp-6 : Depends: gcc-6-base (= 6.3.0-12ubuntu2) but 6.3.0-18ubuntu2~16.04 is to be installed

再次。

$ sudo apt install gcc-6-base
...
gcc-6-base is already the newest version (6.3.0-18ubuntu2~16.04).

所以这里我不知道到底出了什么问题。需要注意的是,16.04版本号末尾有一个字符串。这似乎很奇怪。我删除了那个包。

$ sudo apt remove gcc-6-base

现在我可以build-essential再次安装。这也将重新安装gcc-6-base

$ sudo apt install build-essential

剩余问题:

$ sudo apt upgrade
...
The following packages have been kept back:
  cpp g++ gcc

问题的根源与上面的类似,gcc-7-base有缺陷,但我无法简单地将其删除,因为我得到了这个:

The following packages have unmet dependencies:
 libgcc1 : Depends: gcc-7-base (= 7.1.0-5ubuntu2~16.04) but it is not going to be installed
 va-driver-all : Depends: mesa-va-drivers but it is not going to be installed or
                          vdpau-va-driver but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

危险区

我通过以下步骤成功解决了这个问题:

$ sudo apt install aptitude
$ sudo dpkg --force-all -P gcc-7-base
$ sudo dpkg --force-all -P gcc-7-base:i386
$ sudo aptitude install gcc-7-base

这非常危险,可能会破坏您的安装。执行dpkg --force-all -P将强制删除包,忽略此包的任何依赖项。随后执行常规操作apt upgrade可能会从您的安装中删除几乎所有相关软件。

我只能通过 usind 从那里恢复aptitude,它解决了我遇到的每个依赖问题。

答案2

我在从 14.04 LTS 升级到 16.04 LTS 时遇到了同样的问题。我写了详细的解决方案这里。但为了方便起见,我将在这里重述要点。

删除所有依赖库( )并使用(方法)autoremove安装所有缺失的库sudo apt-get -f install-f--fix-missing

sudo apt-get autoremove
sudo apt-get -f install
sudo apt-get update
sudo apt-get upgrade 

ubuntu toolchain从 PPA安装

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

安装aptitude

sudo apt install aptitude

递归尝试安装损坏的库,直到通过升级或修复特定库解决冲突。在我的例子中,我必须修复libstdc++6

$ sudo aptitude -f install build-essential
The following NEW packages will be installed:
  build-essential cpp{a} cpp-5{a} g++{a} g++-5{a} gcc{a} gcc-5{a} libasan2{a} libcc1-0{ab} 
  libcilkrts5{a} libgcc-5-dev{a} liblsan0{ab} libmpx0{a} libstdc++-5-dev{a} 
The following packages will be upgraded:
  gcc-5-base libstdc++6{b} 
2 packages upgraded, 14 newly installed, 0 to remove and 5 not upgraded.
Need to get 29.6 MB of archives. After unpacking 100 MB will be used.
The following packages have unmet dependencies:
 liblsan0 : Depends: gcc-9-base (= 9.3.0-10ubuntu2~16.04) but 9.3.0-11ubuntu0~14.04 is installed.
 libcc1-0 : Depends: gcc-9-base (= 9.3.0-10ubuntu2~16.04) but 9.3.0-11ubuntu0~14.04 is installed.
 libstdc++6 : Depends: gcc-9-base (= 9.3.0-10ubuntu2~16.04) but 9.3.0-11ubuntu0~14.04 is installed.

build-essential需要gcc-5

$ sudo apt-get -f install gcc-5

The following packages have unmet dependencies:
 gcc-5 : Depends: cpp-5 (= 5.5.0-12ubuntu1~16.04) but it is not going to be installed
         Depends: gcc-5-base (= 5.5.0-12ubuntu1~16.04) but 5.4.0-6ubuntu1~16.04.12 is to be installed
         Depends: libcc1-0 (>= 5.5.0-12ubuntu1~16.04) but it is not going to be installed
         Depends: libgcc-5-dev (= 5.5.0-12ubuntu1~16.04) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

gcc-5反过来又取决于cpp-5

$ sudo apt-get -f install cpp-5

The following packages have unmet dependencies:
 cpp-5 : Depends: gcc-5-base (= 5.5.0-12ubuntu1~16.04) but 5.4.0-6ubuntu1~16.04.12 is to be installed

cpp-5取决于gcc-5-base。在这里你可以看到有一个特定的冲突。Aptitide 提供了多种解决冲突的选择。在我的例子中,升级libstdc++6解决了问题。

$ sudo aptitude -f install gcc-5-base
The following packages will be REMOVED:  
  gcc-5-base{u} 
0 packages upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
Need to get 0 B of archives. After unpacking 67.6 kB will be freed.
The following packages have unmet dependencies:
 libstdc++6 : Depends: gcc-5-base (= 5.4.0-6ubuntu1~16.04.12) but it is not going to be installed.
open: 115; closed: 488; defer: 35; conflict: 58                                                          .The following actions will resolve these dependencies:

     Keep the following packages at their current version:                        
1)     gcc-5-base [5.4.0-6ubuntu1~16.04.12 (now, xenial-security, xenial-updates)]

Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

      Upgrade the following packages:                                                                     
1)      libstdc++6 [5.4.0-6ubuntu1~16.04.12 (now, xenial-security, xenial-updates) -> 9.3.0-10ubuntu2~16.0

最后,现在冲突已解决,请尝试build-essential再次安装。

$ sudo aptitude -f install build-essential

祝你好运!

答案3

我有同样的问题,但解决方案实际上非常简单,所以它说:以下软件包具有未满足的依赖关系:

 build-essential : Depends: gcc (>= 4:5.2) but it is not going to be installed
                   Depends: g++ (>= 4:5.2) but it is not going to be installed

只需安装“依赖”上的包即可:

apt-get install gcc

然后它会说:

The following packages have unmet dependencies:
 gcc : Depends: cpp (= 4:9.2.1-3.1) but 4:8.3.0-1 is to be installed
       Depends: gcc-9 (>= 9.2.1-1~) but it is not going to be installed

然后做 :

apt-get install cpp 

您可以看到depends:从depends:gcc更改为depends:cpp,然后一遍又一遍地执行此操作,直到不再出现相同的错误,然后:

sudo apt install build-essential 

相关内容