3

我在我的alloca一个项目中使用该功能,并决定使用 CMake 来确保它可用。所以我将这一点添加到我的 CMakeLists.txt 文件中:

include(CheckSymbolExists)
check_symbol_exists(alloca stdlib.h;cstdlib ALLOCA_EXISTS)
if (NOT ALLOCA_EXISTS)
    message(FATAL_ERROR "Platform does not support alloca")
endif ()

当我运行 CMake 时,这是输出的(相关部分):

-- Looking for alloca
-- Looking for alloca - found
CMake Error at CMakeLists.txt:11 (message):
  Platform does not support alloca


-- Configuring incomplete, errors occurred!

那么显示的代码如何找到函数但没有设置变量?或者是别的什么?

4

1 回答 1

1

指定标题时必须添加引号:

check_symbol_exists(alloca "stdlib.h;cstdlib" ALLOCA_EXISTS)

否则,ALLOCA_EXISTS将被忽略并cstdlib使用 value 创建一个变量TRUE

于 2017-06-17T11:30:08.377 回答