平时用run文件安装一直没问题的,直到有一次安装NVIDIA-Linux-x86_64-580.105.08.run报错了:
make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_rsa.o] Error 1 gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_sha.o] Error 1 CC [M] /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_x509.o CC [M] /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_rsa_ext.o make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_aead_aes_gcm.o] Error 1 CC [M] /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/nvlink_linux.o gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? CC [M] /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/nvlink_caps.o gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_internal_crypt_lib.o] Error 1 gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? CC [M] /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/linux_nvswitch.o make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_hkdf_sha.o] Error 1 make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_hmac_sha.o] Error 1 make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_ec.o] Error 1 CC [M] /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/procfs_nvswitch.o gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_rsa_ext.o] Error 1 gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/libspdm_x509.o] Error 1 CC [M] /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/i2c_nvswitch.o gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/linux_nvswitch.o] Error 1 gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/nvlink_caps.o] Error 1 make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/nvlink_linux.o] Error 1 gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/i2c_nvswitch.o] Error 1 gcc: error: unrecognized command line option '-mharden-sls=all'; did you mean '-mhard-float'? make[2]: *** [scripts/Makefile.build:297: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel/nvidia/procfs_nvswitch.o] Error 1 make[2]: Target '__build' not remade because of errors. make[1]: *** [Makefile:1930: /tmp/makeself.jVFX6q9P/NVIDIA-Linux-x86_64-580.105.08/kernel] Error 2 make[1]: Target 'modules' not remade because of errors. make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-156-generic' make: *** [Makefile:138: modules] Error 2 ERROR: The nvidia kernel module was not created. ERROR: Installation has failed. Please see the file '/var/log/nvidia-installer.log' for details. You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.
这个错误是说,内核是用 gcc 11.4 编的,但你用 gcc 7.5 去编 NVIDIA 模块,结果触发了新内核 CFLAGS(例如 -mharden-sls=all)而老 gcc 不认识,于是大量报错。
把 .run 安装器改为用 gcc-11(最好就是 11.4)即可解决。
sudo apt update
sudo apt install -y build-essential dkms linux-headers-$(uname -r)
sudo apt install -y gcc-11 g++-11
gcc-11 --version
sudo CC=/usr/bin/gcc-11 HOSTCC=/usr/bin/gcc-11 \
sh ./NVIDIA-Linux-x86_64-580.105.08.run \
--dkms --ui=none --no-questions --no-cc-version-check
按照上面这个命令跑一遍就可以了,最好最后再reboot一下~
(base) mcj@ubuntu:~$ sudo CC=/usr/bin/gcc-11 HOSTCC=/usr/bin/gcc-11 \ sh ./NVIDIA-Linux-x86_64-580.105.08.run \ --dkms --ui=none --no-questions --no-cc-version-check Verifying archive integrity... OK Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 580.105.08.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Welcome to the NVIDIA Software Installer for Unix/Linux Detected 48 CPUs online; setting concurrency level to 32. Scanning the initramfs with lsinitramfs... Executing: /usr/bin/lsinitramfs -l /boot/initrd.img-5.15.0-156-generic Multiple kernel module types are available for this system. Which would you like to use? (Answer: MIT/GPL) Installing NVIDIA driver version 580.105.08. Performing CC sanity check with CC="/usr/bin/gcc-11". Performing CC check. Kernel source path: '/lib/modules/5.15.0-156-generic/build' Kernel output path: '/lib/modules/5.15.0-156-generic/build' Performing Compiler check. Performing Dom0 check. Performing Xen check. Performing PREEMPT_RT check. Performing vgpu_kvm check. Cleaning kernel module build directory. Building kernel modules: [##############################] 100% Kernel module compilation complete. Unable to determine if Secure Boot is enabled: No such file or directory Kernel messages: [127028.257570] audit: type=1400 audit(1762608197.462:874): apparmor="STATUS" operation="profile_remove" profile="unconfined" name="lxd-autodl-201-2_</var/snap/lxd/common/lxd>" pid=3955896 comm="apparmor_parser" [127068.951433] audit: type=1400 audit(1762608238.157:875): apparmor="STATUS" operation="profile_remove" profile="unconfined" name="lxd_dnsmasq-lxdbr0_</var/snap/lxd/common/lxd>" pid=3959162 comm="apparmor_parser" [127144.026010] nvidia-nvlink: Unregistered Nvlink Core, major device number 511 [127390.711336] audit: type=1400 audit(1762608559.943:876): apparmor="DENIED" operation="open" profile="ubuntu_pro_esm_cache//apt_methods_gpgv" name="/dev/tty" pid=4006441 comm="apt-key" requested_mask="wr" denied_mask="wr" fsuid=105 ouid=0 [127390.947279] audit: type=1400 audit(1762608560.179:877): apparmor="DENIED" operation="open" profile="ubuntu_pro_esm_cache//apt_methods_gpgv" name="/dev/tty" pid=4006480 comm="apt-key" requested_mask="wr" denied_mask="wr" fsuid=105 ouid=0 [127400.618293] audit: type=1400 audit(1762608569.848:878): apparmor="STATUS" operation="profile_load" profile="unconfined" name="lxd_dnsmasq-lxdbr0_</var/snap/lxd/common/lxd>" pid=4007757 comm="apparmor_parser" [127552.705250] audit: type=1400 audit(1762608721.957:879): apparmor="DENIED" operation="open" profile="ubuntu_pro_esm_cache//apt_methods_gpgv" name="/dev/tty" pid=4025192 comm="apt-key" requested_mask="wr" denied_mask="wr" fsuid=105 ouid=0 [127552.979337] audit: type=1400 audit(1762608722.233:880): apparmor="DENIED" operation="open" profile="ubuntu_pro_esm_cache//apt_methods_gpgv" name="/dev/tty" pid=4025251 comm="apt-key" requested_mask="wr" denied_mask="wr" fsuid=105 ouid=0 [128090.129929] nvidia-nvlink: Nvlink Core is being initialized, major device number 511 [128090.129936] NVRM: loading NVIDIA UNIX Open Kernel Module for x86_64 580.105.08 Release Build (dvs-builder@U22-I3-B10-02-5) Wed Oct 29 22:29:53 UTC 2025 [128090.385198] nvidia-modeset: Loading NVIDIA UNIX Open Kernel Mode Setting Driver for x86_64 580.105.08 Release Build (dvs-builder@U22-I3-B10-02-5) Wed Oct 29 22:16:05 UTC 2025 [128090.389974] [drm] [nvidia-drm] [GPU ID 0x00003b00] Loading driver [128090.390078] [drm] Initialized nvidia-drm 0.0.0 20160202 for 0000:3b:00.0 on minor 1 [128090.390086] [drm] [nvidia-drm] [GPU ID 0x00005e00] Loading driver [128090.390151] [drm] Initialized nvidia-drm 0.0.0 20160202 for 0000:5e:00.0 on minor 2 [128090.390162] [drm] [nvidia-drm] [GPU ID 0x0000b100] Loading driver [128090.390218] [drm] Initialized nvidia-drm 0.0.0 20160202 for 0000:b1:00.0 on minor 3 [128090.390225] [drm] [nvidia-drm] [GPU ID 0x0000d900] Loading driver [128090.390281] [drm] Initialized nvidia-drm 0.0.0 20160202 for 0000:d9:00.0 on minor 4 [128090.398786] [drm] [nvidia-drm] [GPU ID 0x0000d900] Unloading driver [128090.398965] [drm] [nvidia-drm] [GPU ID 0x0000b100] Unloading driver [128090.399135] [drm] [nvidia-drm] [GPU ID 0x00005e00] Unloading driver [128090.399262] [drm] [nvidia-drm] [GPU ID 0x00003b00] Unloading driver [128090.473162] nvidia-modeset: Unloading [128090.642555] nvidia-nvlink: Unregistered Nvlink Core, major device number 511 WARNING: nvidia-installer was forced to guess the X library path '/usr/lib' and X module path '/usr/lib/xorg/modules'; these paths were not queryable from the system. If X fails to find the NVIDIA X driver module, please install the `pkg-config` utility and the X.Org SDK/development package for your distribution and reinstall the driver. Install NVIDIA's 32-bit compatibility libraries? (Answer: Yes) WARNING: This NVIDIA driver package includes Vulkan components, but no Vulkan ICD loader was detected on this system. The NVIDIA Vulkan ICD will not function without the loader. Most distributions package the Vulkan loader; try installing the "vulkan-loader", "vulkan-icd-loader", or "libvulkan1" package. Would you like to register the kernel module sources with DKMS? This will allow DKMS to automatically build a new module, if your kernel changes later. (Answer: Yes) Registering the kernel modules with DKMS:: Generating DKMS tarball [##############################] 100% Skipping GLVND file: "libOpenGL.so.0" Skipping GLVND file: "libOpenGL.so" Skipping GLVND file: "libGLESv1_CM.so.1.2.0" Skipping GLVND file: "libGLESv1_CM.so.1" Skipping GLVND file: "libGLESv1_CM.so" Skipping GLVND file: "libGLESv2.so.2.1.0" Skipping GLVND file: "libGLESv2.so.2" Skipping GLVND file: "libGLESv2.so" Skipping GLVND file: "libGLdispatch.so.0" Skipping GLVND file: "libGLX.so.0" Skipping GLVND file: "libGLX.so" Skipping GLVND file: "libGL.so.1.7.0" Skipping GLVND file: "libGL.so.1" Skipping GLVND file: "libGL.so" Skipping GLVND file: "libEGL.so.1.1.0" Skipping GLVND file: "libEGL.so.1" Skipping GLVND file: "libEGL.so" Skipping GLVND file: "./32/libOpenGL.so.0" Skipping GLVND file: "libOpenGL.so" Skipping GLVND file: "./32/libGLdispatch.so.0" Skipping GLVND file: "./32/libGLESv2.so.2.1.0" Skipping GLVND file: "libGLESv2.so.2" Skipping GLVND file: "libGLESv2.so" Skipping GLVND file: "./32/libGLESv1_CM.so.1.2.0" Skipping GLVND file: "libGLESv1_CM.so.1" Skipping GLVND file: "libGLESv1_CM.so" Skipping GLVND file: "./32/libGL.so.1.7.0" Skipping GLVND file: "libGL.so.1" Skipping GLVND file: "libGL.so" Skipping GLVND file: "./32/libGLX.so.0" Skipping GLVND file: "libGLX.so" Skipping GLVND file: "./32/libEGL.so.1.1.0" Skipping GLVND file: "libEGL.so.1" Skipping GLVND file: "libEGL.so" Searching for conflicting files:: Searching [##############################] 100% Installing 'NVIDIA Accelerated Graphics Driver for Linux-x86_64' (580.105.08):: Installing [##############################] 100% Driver file installation is complete. Running post-install sanity check:: Checking [##############################] 100% Post-install sanity check passed. Installation of the NVIDIA Accelerated Graphics Driver for Linux-x86_64 (version: 580.105.08) is now complete.