cmake config_error ai_generated true

CMake Error: CMake Error in CMakeLists.txt: Unknown CMake command "my_custom_function".

ID: cmake/unknown-cmake-command

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2023-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
cmake 2.8 active
cmake 3.0 active
cmake 3.16 active
cmake 3.28 active

Root Cause

A CMakeLists.txt calls a function or macro that is not defined, due to a missing include, typo, or unsupported module.

generic

中文

CMakeLists.txt调用了一个未定义的函数或宏,原因是缺少include、拼写错误或不支持的模块。

Official Documentation

https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#command-invocations

Workarounds

  1. 95% success Check for typos: ensure the command is spelled correctly (e.g., 'target_link_libraries' not 'target_link_library').
    Check for typos: ensure the command is spelled correctly (e.g., 'target_link_libraries' not 'target_link_library').
  2. 90% success If the command is from a custom module, add include(MyModule) before the call, or use include(path/to/module.cmake).
    If the command is from a custom module, add include(MyModule) before the call, or use include(path/to/module.cmake).
  3. 80% success If the command is from an older CMake version, upgrade CMake or use a compatibility wrapper: cmake_minimum_required(VERSION 3.10).
    If the command is from an older CMake version, upgrade CMake or use a compatibility wrapper: cmake_minimum_required(VERSION 3.10).

中文步骤

  1. 检查拼写错误:确保命令拼写正确(例如'target_link_libraries'而不是'target_link_library')。
  2. 如果命令来自自定义模块,在调用前添加include(MyModule),或使用include(path/to/module.cmake)。
  3. 如果命令来自旧版CMake,升级CMake或使用兼容性包装:cmake_minimum_required(VERSION 3.10)。

Dead Ends

Common approaches that don't work:

  1. Typing the command name in a different case (e.g., 'My_Function' vs 'my_function') 30% fail

    CMake commands are case-insensitive but must match exactly; case issues rarely cause this error.

  2. Adding the command as a comment to suppress the error 100% fail

    Comments are ignored; the command must be defined or removed.

  3. Installing a third-party module without including it 80% fail

    The module must be included with include() or find_package() before use.