# CMake 错误：check_cxx_source_compiles 失败，错误信息：<编译器错误输出>

- **ID:** `cmake/check-cxx-source-compiles-failed`
- **领域:** cmake
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

提供给 check_cxx_source_compiles() 的 C++ 源代码片段编译失败，通常是由于缺少头文件、语法错误或编译器标志不兼容。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CMake 3.10 | active | — | — |
| CMake 3.16 | active | — | — |
| CMake 3.22 | active | — | — |
| CMake 3.27 | active | — | — |

## 解决方案

1. ```
   Inspect the compiler error output to identify missing headers or syntax issues, then fix the source snippet or add required include directories.
   ```
2. ```
   Set CMAKE_REQUIRED_FLAGS or CMAKE_REQUIRED_LIBRARIES to match the project's compile environment.
   ```

## 无效尝试

- **Adding -Werror or other flags globally to suppress warnings, hoping the snippet compiles** — The error is usually a hard compile failure, not a warning. Adding flags may introduce more issues. (90% 失败率)
- **Removing the check entirely, assuming the feature is available** — The check is there for a reason; removing it may lead to runtime errors or build failures later. (85% 失败率)
- **Copying the exact snippet into a standalone file and compiling it manually, then ignoring the CMake error** — Even if it compiles manually, the CMake check may have different include paths or flags; manual success does not guarantee CMake success. (70% 失败率)
