cmake
config_error
ai_generated
true
CMake 错误:目标 "mycudatarget" 的 CUDA_ARCHITECTURES 为空
CMake Error: CUDA_ARCHITECTURES is empty for target "mycudatarget"
ID: cmake/cuda-architectures-empty
90%修复率
88%置信度
1证据数
2023-12-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| CMake 3.18 | active | — | — | — |
| CMake 3.19 | active | — | — | — |
| CMake 3.20 | active | — | — | — |
根因分析
CMake 3.18+ 要求为所有启用 CUDA 的目标设置 CUDA_ARCHITECTURES;空值或未设置变量会触发此错误,以防止不支持的架构代码。
English
CMake 3.18+ requires CUDA_ARCHITECTURES to be set for all CUDA-enabled targets; an empty value or unset variable triggers this error to prevent unsupported architecture code.
官方文档
https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html解决方案
-
set_target_properties(mycudatarget PROPERTIES CUDA_ARCHITECTURES "75;80") # Or use the native arch detection: set(CMAKE_CUDA_ARCHITECTURES "native")
-
set(CMAKE_CUDA_ARCHITECTURES "75;80") add_library(mycudatarget CUDA mycuda.cu)
无效尝试
常见但无效的做法:
-
100% 失败
CMake interprets OFF as an empty string, still triggering the error.
-
100% 失败
An empty string is still empty; CMake requires a non-empty list of architectures.