2017-06-16 75 views
2

我在其中一個項目中使用alloca函數,並決定使用CMake來確保它可用。所以我說這一點對我的CMakeLists.txt文件:爲什麼這個CMake腳本找到「alloca」並仍然失敗?

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! 

那麼怎麼來的顯示代碼發現函數但不設置變量?或者是別的什麼?

回答

1

當您指定的標題,您必須添加引號:

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

否則,ALLOCA_EXISTS被忽略和可變cstdlib與價值TRUE創建。