在Mac OSX 10.11.6上找不到clock_gettime

时间:2016-10-31 09:52:13

标签: c macos cmake clock

我正在尝试在Mac上构建I-Simpa。

当我尝试在spps阶段构建时,我收到有关clock_gettime未找到的错误。我尝试在MSDN中更改spps目录中的CMakelists.txt:

check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)

if (NOT HAVE_CLOCK_GETTIME)
    set(CMAKE_EXTRA_INCLUDE_FILES time.h)
    CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
    SET(CMAKE_EXTRA_INCLUDE_FILES)
endif()

但是我得到了错误:

  

未知的CMake命令" CHECK_FUNCTION_EXISTS"

1 个答案:

答案 0 :(得分:0)

我猜你改变了CMakeLists.txt的this part

if (UNIX)
  include(CheckLibraryExists)
  check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME )
  if(NOT HAVE_CLOCK_GETTIME)
    message(FATAL_ERROR "clock_gettime not found")
  endif(NOT HAVE_CLOCK_GETTIME)
endif(UNIX)

如您所见,CMake已知check_library_exists,因为先前已使用include(CheckLibraryExists)包含相应的模块。

同样,这只是一个猜测,但我很确定你没有包含CHECK_FUNCTION_EXISTS的模块。尝试:

check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)

if (NOT HAVE_CLOCK_GETTIME)
    #**************************#
    include(CheckFunctionExists)
    #**************************#
    set(CMAKE_EXTRA_INCLUDE_FILES time.h)
    CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
    SET(CMAKE_EXTRA_INCLUDE_FILES)
endif()

这将删除" Unknown CMake命令"错误,但在Mac OS上无法使用clock_gettime。有关替代方案,请参阅this question