我只是想用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)
Code snippet in
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
不是很了解,所以我无法弄清楚症结所在。
这里是my log file outputed by CMake
希望熟悉CMake的 friend 帮帮我。提前致谢。
最佳答案
错误信息
CMake Error: The source directory "../build/CMakeFiles/CMakeTmp" does not exist.
如果将相对 路径用作构建目录,则这是可能的。
虽然在文档中没有明确说明(也没有被 CMake 本身检查),但最好使用绝对路径作为构建目录。
因为 CMake 项目的 build 目录没有被设计成移动到其他地方(甚至在其他机器上),所以没有理由使用相对路径
关于c++ - CMake 无法检测 gcc 内置函数,如 sqrt、pow、exp 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43412943/