CMake 无法检测 gcc 内置函数,如 sqrt、pow、exp 等

CMake can't detect gcc built-in functions such as sqrt, pow ,exp and so on

本文关键字:sqrt pow exp 函数 检测 gcc 内置 CMake      更新时间:2023-10-16

我只是想使用cmake检测是否存在GCC的某些内置功能。因此,我使用check_function_exists命令进行一些检查工作。这是CMakeLists.txt中的我的代码片段。

include (CheckFunctionExists)
set (CMAKE_REQUIRED_INCLUDES math.h)
set (CMAKE_REQUIRED_LIBRARIES m)
check_function_exists(sqrt HAVE_SQRT)
check_function_exists (pow HAVE_POW)
check_function_exists (exp HAVE_EXP)
check_function_exists (log HAVE_LOG)

TutorialConfig.h.in中的代码段

// the configured options and settings for Tutorial
#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR  @Tutorial_VERSION_MINOR@
#cmakedefine USE_MYMATH
#cmakedefine HAVE_SQRT
#cmakedefine HAVE_POW
#cmakedefine HAVE_LOG
#cmakedefine HAVE_EXP

  但是,当我在源目录下执行Cmake命令时,目录。我有这样的错误,很奇怪。

-- The C compiler identification is GNU 7.0.0
-- The CXX compiler identification is GNU 7.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for sqrt
CMake Error: The source directory "../build/CMakeFiles/CMakeTmp" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
CMake Error at /usr/share/cmake/Modules/CheckFunctionExists.cmake:70 (try_compile):
  Failed to configure test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:23 (check_function_exists)

  但是,错误消息中声称的目录确实存在。

$ ls -la ../build/CMakeFiles/CMakeTmp 
  total 0
  drwxrwxrwx 1 root root 0 Apr 14 21:41 .
  drwxrwxrwx 1 root root 0 Apr 14 20:32 ..

  我不是CMake的专家,所以我不知道什么是关键。

  这是我的日志文件,由cmake

输出

希望任何熟悉CMAKE的人都可以帮助我。预先感谢。

错误消息

CMake Error: The source directory "../build/CMakeFiles/CMakeTmp" does not exist.

如果A 相对路径用作构建目录。

虽然在文档中未明确说明它(并且未经CMAKE本身检查(,但最好将绝对路径用作build Directory 。


因为构建目录 cmake Project的不是设计为移动到其他位置(甚至在其他机器上(,因此没有理由使用相对路径为此。