【问题标题】:Why does this CMake script find "alloca" and still fail?为什么这个 CMake 脚本找到“alloca”但仍然失败?
【发布时间】:2017-11-18 15:34:11
【问题描述】:

我在我的一个项目中使用了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!

那么为什么显示的代码找到了函数但没有设置变量?还是别的什么?

【问题讨论】:

    标签: c++ cmake alloca


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-05-01
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 2013-07-27
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多