我正在处理 CMake Tutorial并与相关的 project files 进行交叉核对我卡在了第 4 步。
说明将这些行添加到顶级 CMakeLists.txt 文件中:
# does this system provide the log and exp functions?
include (CheckFunctionExists)
check_function_exists (log HAVE_LOG)
check_function_exists (exp HAVE_EXP)
如前所述,这是一个简单的测试,因为地球上几乎每个系统都有 log
和 exp
。但它失败了。生成 Makefile 时,我看到了
-- Looking for log
-- Looking for log - not found
-- Looking for exp
-- Looking for exp - not found
如果我深入挖掘,运行 cmake --trace
,我会看到以下几行:
.../tutorial/src/CMakeLists.txt(19): include( CheckFunctionExists )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(32): macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE )
.../tutorial/src/CMakeLists.txt(20): check_function_exists(log HAVE_LOG )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(33): if(HAVE_LOG MATCHES ^HAVE_LOG$ )
.../tutorial/src/CMakeLists.txt(21): check_function_exists(exp HAVE_EXP )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(33): if(HAVE_EXP MATCHES ^HAVE_EXP$ )
在 CheckFunctionExists.cmake
文件中,该测试没有 else
条件。我是 cmake 的新手,但测试在我看来是真实的。我错过了什么?
CentOS 7,cmake 2.8.12.2
最佳答案
CheckFunctionExists
已知有严重的缺陷。参见 documentation .
在您的情况下,您可能会遇到第一个陷阱。 log
和 exp
函数在许多平台上都是内在的内联函数。它们无法在链接时检测到。
推荐的替换是CheckSymbolExists
。不幸的是,您的 cmake 版本不支持此功能。您至少需要升级到 3.0.2 才能正常工作。
关于c++ - CMake check_function_exists 没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50220242/