cmake build_error ai_generated partial

CMake 错误:Ninja 生成器不支持 CXX 编译器 'clang++',因为它不是已知的编译器。

CMake Error: The Ninja generator does not support the CXX compiler 'clang++' because it is not a known compiler.

ID: cmake/generator-ninja-missing-compiler

其他格式: JSON · Markdown 中文 · English
70%修复率
84%置信度
1证据数
2024-01-10首次发现

版本兼容性

版本状态引入弃用备注
CMake 3.10 active
CMake 3.16 active
CMake 3.20 active
Ninja 1.10 active
Ninja 1.11 active

根因分析

CMake 的 Ninja 生成器有一个硬编码的支持编译器列表;如果编译器不在该列表中(例如自定义构建的 clang 或不同版本),CMake 会拒绝它。

English

CMake's Ninja generator has a hardcoded list of supported compilers; if the compiler is not in that list (e.g., a custom build of clang or a different version), CMake rejects it.

generic

官方文档

https://cmake.org/cmake/help/latest/generator/Ninja.html

解决方案

  1. 改用 'Unix Makefiles' 生成器:cmake -G "Unix Makefiles" ..
  2. 设置 CMAKE_GENERATOR 为 Ninja 并设置 CMAKE_CXX_COMPILER 为已知编译器如 g++:cmake -G Ninja -DCMAKE_CXX_COMPILER=g++ ..
  3. 升级 CMake 到支持你的编译器的版本。例如,CMake 3.20+ 增加了对更新 clang 版本的支持。检查发布说明。

无效尝试

常见但无效的做法:

  1. 60% 失败

    If the project requires clang-specific features (e.g., libc++), using g++ may cause compilation errors.

  2. 70% 失败

    The issue is not version-specific; CMake's Ninja generator has a whitelist of compiler IDs. Even standard clang may fail if CMake version is old.

  3. 30% 失败

    This works but may not preserve Ninja's build speed; also, the project may have Ninja-specific custom commands.