Skip to content

CUDA 与 GCC 版本兼容性指南

在使用 NVIDIA CUDA 工具包进行开发时,确保所用的 GCC(GNU 编译器集合)版本与 CUDA 版本兼容至关重要。不兼容的组合可能导致编译错误或运行时问题。以下是各主要 CUDA 版本与其支持的 GCC 版本的对应关系:

CUDA 与 GCC 版本对应表

CUDA 版本 支持的 GCC 版本范围 说明
9.2 ≤ 7.x 最后支持 GCC 7 的版本
10.1 ≤ 8.x 添加对 GCC 8 的支持
10.2 ≤ 8.x 继续支持 GCC 8
11.0 ≤ 9.x 添加对 GCC 9 的支持
11.1 ≤ 10.x 添加对 GCC 10 的支持
11.3 ≤ 10.x 继续支持 GCC 10
11.4 ≤ 11.x 添加对 GCC 11 的支持
11.7 ≤ 11.x 继续支持 GCC 11
11.8 ≤ 11.x 继续支持 GCC 11
12.0 ≤ 12.x 添加对 GCC 12 的支持
12.3 ≤ 12.2 不支持 GCC 13 及以上版本
12.4 ≤ 13.x 添加对 GCC 13 的支持
12.6 ≤ 13.x 不支持 GCC 14 及以上版本 (维基百科)

请注意,使用高于支持范围的 GCC 版本可能导致编译失败或运行时错误。例如,在 Fedora 40 上,默认的 GCC 版本为 14.x,而 CUDA 12.6 不支持 GCC 14,可能会出现如下错误信息:(negativo17.org)

#error -- unsupported GNU version! gcc versions later than 13 are not supported!

在这种情况下,建议使用支持的 GCC 版本进行编译。您可以通过以下方式指定 nvcc 使用的 GCC 版本:

nvcc --compiler-bindir /path/to/supported/gcc

其中,/path/to/supported/gcc 是支持的 GCC 版本的路径。您可以通过安装多个 GCC 版本并在编译时指定使用的版本来解决兼容性问题。(Stack Overflow)

参考资料

https://blog.csdn.net/muxuen/article/details/135298656 https://zhuanlan.zhihu.com/p/640797289 https://blog.csdn.net/ustczhng2012/article/details/114369985 https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html