cmake
config_error
ai_generated
true
CMake错误:目标"mytarget"的CUDA_ARCHITECTURES为空
CMake Error: CUDA_ARCHITECTURES is empty for target "mytarget"
ID: cmake/cuda-architecture-unknown
80%修复率
85%置信度
1证据数
2023-03-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| CMake 3.18 | active | — | — | — |
| CMake 3.19 | active | — | — | — |
| CMake 3.20 | active | — | — | — |
| CMake 3.21 | active | — | — | — |
| CMake 3.22 | active | — | — | — |
| CMake 3.23 | active | — | — | — |
| CMake 3.24 | active | — | — | — |
| CMake 3.25 | active | — | — | — |
| CMake 3.26 | active | — | — | — |
| CMake 3.27 | active | — | — | — |
| CMake 3.28 | active | — | — | — |
| CMake 3.29 | active | — | — | — |
| CMake 3.30 | active | — | — | — |
| CUDA 11.0 | active | — | — | — |
| CUDA 11.8 | active | — | — | — |
| CUDA 12.0 | active | — | — | — |
根因分析
CMake 3.18及以上版本要求显式指定CUDA架构;当CMAKE_CUDA_ARCHITECTURES未设置或设置为空时,编译失败。
English
CMake 3.18+ requires explicit CUDA architectures; when CMAKE_CUDA_ARCHITECTURES is not set or set to empty, compilation fails.
官方文档
https://cmake.org/cmake/help/latest/policy/CMP0104.html解决方案
-
Set CMAKE_CUDA_ARCHITECTURES globally before project() call: set(CMAKE_CUDA_ARCHITECTURES "75;80")
-
Use target property: set_property(TARGET mytarget PROPERTY CUDA_ARCHITECTURES "75;80")
-
Set environment variable: export CMAKE_CUDA_ARCHITECTURES=75;80 before running cmake
无效尝试
常见但无效的做法:
-
Setting CMAKE_CUDA_ARCHITECTURES to empty string in CMakeLists.txt
95% 失败
CMake interprets empty string as no architectures specified, triggering the same error.
-
Removing all CUDA-related lines from CMakeLists.txt
80% 失败
Without any architecture, CMake defaults to empty, causing the error.
-
Setting CMAKE_CUDA_ARCHITECTURES to 'all' on older CUDA versions
60% 失败
'all' may include unsupported architectures, leading to compilation failures.