# CMake错误：目标"mytarget"的CUDA_ARCHITECTURES为空

- **ID:** `cmake/cuda-architecture-unknown`
- **领域:** cmake
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

CMake 3.18及以上版本要求显式指定CUDA架构；当CMAKE_CUDA_ARCHITECTURES未设置或设置为空时，编译失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 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 | — | — |

## 解决方案

1. ```
   Set CMAKE_CUDA_ARCHITECTURES globally before project() call: set(CMAKE_CUDA_ARCHITECTURES "75;80")
   ```
2. ```
   Use target property: set_property(TARGET mytarget PROPERTY CUDA_ARCHITECTURES "75;80")
   ```
3. ```
   Set environment variable: export CMAKE_CUDA_ARCHITECTURES=75;80 before running cmake
   ```

## 无效尝试

- **Setting CMAKE_CUDA_ARCHITECTURES to empty string in CMakeLists.txt** — CMake interprets empty string as no architectures specified, triggering the same error. (95% 失败率)
- **Removing all CUDA-related lines from CMakeLists.txt** — Without any architecture, CMake defaults to empty, causing the error. (80% 失败率)
- **Setting CMAKE_CUDA_ARCHITECTURES to 'all' on older CUDA versions** — 'all' may include unsupported architectures, leading to compilation failures. (60% 失败率)
