升级到 Ubuntu 18.04 build-essential 后,g++、gcc 和 cpp 保留了损坏的软件包

升级到 Ubuntu 18.04 build-essential 后,g++、gcc 和 cpp 保留了损坏的软件包

从 16.04 build-essential、g++、gcc 和 cpp 升级到 Ubuntu 18.04 后E: Unable to correct problems, you have held broken packages.

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


$ sudo apt-get install gcc
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:
 gcc : Depends: gcc-7 (>= 7.3.0-12~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

g++ 和 cpp 的输出类型相同

如何解决这个问题?

答案1

我也遇到过同样的问题 - 在 Ubuntu 16.04 上工具链测试构建 PPA适用于 gcc 和 clang 构建,包括gcc-7。在升级到 18.04 期间,安装过程禁用了第三方存储库,其中包括此 PPA。

为了修复这个问题,请尝试(重新)将工具链 PPA 添加到你的 apt 源列表中:

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

然后,在安装时build-essential,它应该成功地gcc-7从工具链 PPA 中选择。

答案2

我遇到了同样的问题,但显然我在安装这些工具时使用了不同的 PPA。

对我来说我修复了它:

sudo add-apt-repository ppa:jonathonf/gcc

答案3

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-essentials再次安装。

$ sudo aptitude -f install build-essential

相关内容