cmake
config_error
ai_generated
true
CMake错误:CMakeLists.txt中:未知的CMake命令"my_custom_function"。
CMake Error: CMake Error in CMakeLists.txt: Unknown CMake command "my_custom_function".
ID: cmake/unknown-cmake-command
95%修复率
90%置信度
1证据数
2023-11-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| cmake 2.8 | active | — | — | — |
| cmake 3.0 | active | — | — | — |
| cmake 3.16 | active | — | — | — |
| cmake 3.28 | active | — | — | — |
根因分析
CMakeLists.txt调用了一个未定义的函数或宏,原因是缺少include、拼写错误或不支持的模块。
English
A CMakeLists.txt calls a function or macro that is not defined, due to a missing include, typo, or unsupported module.
官方文档
https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#command-invocations解决方案
-
检查拼写错误:确保命令拼写正确(例如'target_link_libraries'而不是'target_link_library')。
-
如果命令来自自定义模块,在调用前添加include(MyModule),或使用include(path/to/module.cmake)。
-
如果命令来自旧版CMake,升级CMake或使用兼容性包装:cmake_minimum_required(VERSION 3.10)。
无效尝试
常见但无效的做法:
-
Typing the command name in a different case (e.g., 'My_Function' vs 'my_function')
30% 失败
CMake commands are case-insensitive but must match exactly; case issues rarely cause this error.
-
Adding the command as a comment to suppress the error
100% 失败
Comments are ignored; the command must be defined or removed.
-
Installing a third-party module without including it
80% 失败
The module must be included with include() or find_package() before use.