如何修复 Unknown CMake command "check_symbol_exists"

如果你有使用 check_symbol_exists(...) 的 CMake 代码,如

CMakeLists.txt
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
check_symbol_exists(atan2 math.h HAVE_ATAN2)

但你得到类似这样的错误消息

error_message.txt
CMake Error at CMakeLists.txt:8 (check_symbol_exists):
  Unknown CMake command "check_symbol_exists".

-- Configuring incomplete, errors occurred!

你需要添加

CMakeLists_fixed.txt
include(CheckSymbolExists)

CMakeLists.txt 的顶部附近(在第一次调用 check_symbol_exists() 之前)。


Check out similar posts by category: CMake