c++ - CMake check_function_exists 没有

标签 c++ cmake

我正在处理 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)

如前所述,这是一个简单的测试,因为地球上几乎每个系统都有 logexp。但它失败了。生成 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 .

在您的情况下,您可能会遇到第一个陷阱。 logexp 函数在许多平台上都是内在的内联函数。它们无法在链接时检测到。

推荐的替换是CheckSymbolExists。不幸的是,您的 cmake 版本不支持此功能。您至少需要升级到 3.0.2 才能正常工作。

关于c++ - CMake check_function_exists 没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50220242/

相关文章:

c++ - 将以毫秒为单位的时间戳转换为boost中的时区

cmake - 目标和变量的作用域行为是否不同?

android - 编译 native_app_glue.c 导致库文件无效

cmake - cpack 生成带有 %files 条目的 RPM,这些条目与 RPM 规范冲突。怎么修?

bash - 通过 CMake 运行 bash 命令

c++ - boost: vector256.hpp: 没有这样的文件或目录

c++ - 传递 std::ifstream 以用作指针

c++ - Python 和 win32 API - 使用 C 文件

c++ - 来自抽象类的 unique_ptr 的 shared_ptr

c++ - bool 在位域定义中安全吗?