cmake
config_error
ai_generated
true
CMake 错误:目标 "mytarget" 的 CUDA_ARCHITECTURES 为空。
CMake Error: CUDA_ARCHITECTURES is empty for target "mytarget".
ID: cmake/missing-cuda-architectures
93%修复率
90%置信度
1证据数
2024-05-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.18 | active | — | — | — |
| 3.20 | active | — | — | — |
| 3.22 | active | — | — | — |
| 3.28 | active | — | — | — |
根因分析
CMake 3.18+ 要求为使用 CUDA 的目标显式指定 CUDA 架构;如果未设置,则默认为空,导致构建失败。
English
CMake 3.18+ requires explicit CUDA architecture specification for targets using CUDA; if not set, it defaults to empty, causing build failure.
官方文档
https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html解决方案
-
设置有效的 CUDA 架构,例如 `set_target_properties(mytarget PROPERTIES CUDA_ARCHITECTURES "75")` 用于 Turing GPU。
-
设置全局架构:在定义目标之前 `set(CMAKE_CUDA_ARCHITECTURES "75;86")`。
无效尝试
常见但无效的做法:
-
Set CMAKE_CUDA_ARCHITECTURES to empty string to bypass the check.
90% 失败
CMake policy CMP0104 enforces non-empty architectures; empty string still triggers the error.
-
Add `set(CMAKE_CUDA_ARCHITECTURES OFF)` to CMakeLists.txt.
80% 失败
OFF is not a valid architecture; CMake interprets it as empty and fails.