当我遇到此错误时,尝试安装g++:
$ sudo apt-get install g++
[sudo] password for eisha:
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++-9 (>= 9.3.0-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.下面是命令$ apt policy g++的输出:
$ apt policy g++
g++:
Installed: (none)
Candidate: 4:9.3.0-1ubuntu2
Version table:
4:9.3.0-1ubuntu2 500
500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages下面是命令$ apt policy g++-9的输出:
$ apt policy g++-9
g++-9:
Installed: (none)
Candidate: 9.3.0-17ubuntu1~20.04
Version table:
9.3.0-17ubuntu1~20.04 500
500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
9.3.0-10ubuntu2 500
500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages是的,我确实尝试过:sudo apt install build-essential,输出类似于这样:
sudo apt install build-essential
[sudo] password for eisha:
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: libc6-dev but it is not going to be installed or
libc-dev
Depends: g++ (>= 4:9.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.是的,我也尝试了sudo apt update,我得到了一个很长的输出,结尾行是:
Last modification reported: Wed, 26 Jan 2022 19:25:00 +0000
Release file created at: Wed, 26 Jan 2022 16:17:36 +0000
W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/focal-updates/restricted/i18n/Translation-en.xz
E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/focal-updates/universe/binary-amd64/Packages.xz
W: Some index files failed to download. They have been ignored, or old ones used instead发布于 2022-01-27 09:06:26
TL;DR:将libc6降级为libc6=2.31-0ubuntu9.2并安装build-essential。
您没有启用所需的存储库。此外,也有坏版本的包。
通过在Ubuntu20.04上运行apt-cache policy g++,我得到:
g++:
Installed: (none)
Candidate: 4:9.3.0-1ubuntu2
Version table:
4:9.3.0-1ubuntu2 500
500 http://mirrors.my mirror.com/ubuntu focal/main amd64 Packages因此,您必须启用main存储库。运行:
sudo add-apt-repository main && sudo apt update在启用main存储库之后。安装正确版本的libc6:
sudo apt install --reinstall libc6=2.31-0ubuntu9.2不要运行apt upgrade。
现在,更新并清理:
sudo apt update
sudo apt clean
sudo apt autoremove
sudo apt -f install现在,安装元包build-essential以安装g++:
sudo apt install aptitude
sudo aptitude -f install build-essential如果上面的方法不起作用,那么试着恢复默认的存储库,并使用aptitude来安装构建必需的:
sudo mkdir ~/answer && cd ~/answer/ && sudo wget https://gist.githubusercontent.com/ishad0w/788555191c7037e249a439542c53e170/raw/3822ba49241e6fd851ca1c1cbcc4d7e87382f484/sources.list && sudo sed -i "s/focal/$(lsb_release -c -s)/" ~/answer/sources.list && sudo mv ~/answer/sources.list /etc/apt/ && sudo apt update && sudo apt upgrade && sudo rm -rf ~/answer
sudo aptitude -f install build-essentialStill没有工作?
编辑您的问题,包括:
sudo apt install libc6-devsudo apt updateapt-cache policy libc6apt-cache policy libc-dev(在加入这些细节后,请向我提交详细资料;)
发布于 2022-01-26 18:47:13
首先,更新包索引sudo apt update。
在Ubuntu20.04上安装C++编译器的推荐方法是安装整个开发包build-essential。
若要安装,请运行以下命令:
$ sudo apt install build-essential然后,要检查它是否已成功安装,请运行:
$ g++ --version您应该得到一个类似于下面的输出:
$ g++ --version
gcc (Ubuntu 9.2.1-17ubuntu1) 9.2.1 20191102https://askubuntu.com/questions/1389433
复制相似问题