cmake config_error ai_generated true

CMake 错误:无法创建名为 'Ninja' 的生成器。生成器 'Ninja' 不可用。使用 'cmake --help' 查看可用生成器列表。

CMake Error: Could not create named generator 'Ninja'. Generator 'Ninja' is not available. Use 'cmake --help' to see a list of available generators.

ID: cmake/generator-ninja-not-found

其他格式: JSON · Markdown 中文 · English
95%修复率
90%置信度
1证据数
2023-07-01首次发现

版本兼容性

版本状态引入弃用备注
3.14 active
3.20 active
3.24 active
3.27 active

根因分析

CMake 使用 -GNinja 调用,但 Ninja 未安装或不在 PATH 中,或者 CMake 安装不包含 Ninja 生成器(例如,最小安装)。

English

CMake was invoked with -GNinja but Ninja is not installed or not in PATH, or the CMake installation does not include the Ninja generator (e.g., minimal install).

generic

官方文档

https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html

解决方案

  1. 安装 Ninja:在 Ubuntu 上运行 'sudo apt-get install ninja-build';在 macOS 上运行 'brew install ninja';在 Windows 上从 https://ninja-build.org/ 下载并添加到 PATH。
  2. 使用其他生成器,例如 Unix Makefiles:cmake -G "Unix Makefiles" ..
  3. 如果 Ninja 已安装但不在 PATH 中,请指定完整路径:cmake -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja ..

无效尝试

常见但无效的做法:

  1. Reinstalling CMake without selecting the Ninja generator option 90% 失败

    The Ninja generator is part of CMake's built-in generators; a reinstall without ensuring Ninja is in PATH does not help.

  2. Setting CMAKE_GENERATOR to Ninja in CMakeLists.txt 95% 失败

    The generator is selected before CMakeLists.txt is parsed, so this setting has no effect; the error occurs at the configuration stage.

  3. Using -G "Ninja Multi-Config" as a substitute 85% 失败

    If Ninja is not installed, the multi-config generator also fails because it requires the same underlying build tool.