安装Nvidia驱动出现 cc: error: unrecognized command-line option ‘-ftrivial-auto-var-init=zero’

在内核 5.19.0-28-generic 上安装 nvidia-driver-525 时,nvidia 安装失败并显示:

dpkg: error processing package nvidia-dkms-525(--configure):
 installed nvidia-dkms-525 package post-installation script subprocess returned error exit status 10

Examining the /var/lib/dkms/nvidia/525.78.01/build/make.log reveals multiple
cc: error: unrecognized command-line option ‘-ftrivial-auto-var-init=zero’

看起来内核 5.19.0-28-generic 需要 gcc-12 才能正确编译 nvidia-driver-525。

因此,切换回 5.15 内核是一种选择。

如果不想切换回内核 5.15,可以直接更新 gcc 。

  1. 删除 nvidia 驱动程序:
sudo apt-get purge *nvidia* && sudo apt-get autoremove
  1. 更新 gcc 并更新替代方案:
sudo apt-get install gcc-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12
  1. 检查 gcc 版本,现在应该显示 v 12.xx:
gcc --version
gcc (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1. 重新安装nvidia驱动:
sudo apt-get install nvidia-driver-525

参考文献

[SOLVED] Nvidia driver failure on Vera because of gcc-11 on updated kernel 5.19.0-28-generic - Linux Mint Forums

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐