Ubuntu 20.04 gcc 报告错误版本

Ubuntu 20.04 gcc 报告错误版本

当我尝试在我的 20.04 LTS 主机上安装 nvidia 专有驱动程序时,我遇到了使用 DKMS 时无法安装的问题。它抱怨内核使用的 gcc 版本 (9.3.0) 与当前 gcc 版本 (9.4.0) 不匹配。升级到最新内核版本后出现此问题。运行 gcc --version 时,它会报告 9.4.0,但 apt show gcc 会报告 9.3.0。

gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0

apt show gcc
Package: gcc
Version: 4:9.3.0-1ubuntu2

lsb_release -a
LSB Version:    core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:    20.04
Codename:   focal

uname -a
Linux xenon 5.4.0-104-generic #118-Ubuntu SMP Wed Mar 2 19:02:41 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

在我看来,问题在于 apt 显示 gcc 包是 9.3.0,但报告却是 9.4.0。

有什么建议 ?


正如评论中所说,我看不到旧版 gcc。我的 sources.list 文件可能是问题所在?它看起来像这样:

###### Ubuntu Main Repos
deb http://archive.ubuntu.com/ubuntu/ focal main restricted multiverse universe
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted multiverse universe
###### Ubuntu Update Repos
deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted multiverse universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted multiverse universe
deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted multiverse universe
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted multiverse universe

答案1

我可以通过将 gcc 暂时降级到 9.3 来绕过这个问题,然后我可以编译 nVidia 驱动程序:

使用 aptitude,我降级并保留了 g++-9,它会自动保留其相关软件包。如果您愿意,也可以使用“apt-mark hold”。

以下是现在我的系统上暂时处于保留状态的软件包:

[HOLD, DEPENDENCIES] cpp-9:amd64 9.3.0-10ubuntu2
[HOLD, DEPENDENCIES] g++-9:amd64 9.3.0-10ubuntu2
[HOLD, DEPENDENCIES] gcc-9:amd64 9.3.0-10ubuntu2
[HOLD, DEPENDENCIES] gcc-9-base:amd64 9.3.0-10ubuntu2
[HOLD, DEPENDENCIES] libasan5:amd64 9.3.0-10ubuntu2
[HOLD, DEPENDENCIES] libgcc-9-dev:amd64 9.3.0-10ubuntu2
[HOLD, DEPENDENCIES] libstdc++-9-dev:amd64 9.3.0-10ubuntu2

一旦使用 gcc 9.4 编译了系统的新内核(即使用:

cat /proc/version

检查)或者当您不再需要重新编译 nVidia 驱动程序时,您应该能够发布持有的 9.4 gcc 升级并将其安装在您的系统上。

编辑:根据您的要求,这里有一个您可以使用的 /etc/apt/sources.list:

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ focal main restricted
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ focal universe
deb-src http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu/ focal multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu focal-security main restricted
deb-src http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
deb-src http://security.ubuntu.com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse
deb-src http://security.ubuntu.com/ubuntu focal-security multiverse

请尝试一下 aptitude。这里有手册,网上也有教程。

相关内容