2017-06-06 27 views
0

我試圖使用CheckIncludeFileCXX模塊來驗證<gsl/gsl>是否存在於系統中。 GSL存在於/usr/local/include/gsl/gsl但一代又在"GSL not found"CheckIncludeFileCXX找不到標題

project(cpp-binaries) 
cmake_minimum_required(VERSION 3.2) 

include(CheckIncludeFileCXX) 
CHECK_INCLUDE_FILE_CXX("gsl/gsl" GSL_LIBRARY) 

if(NOT GSL_LIBRARY) 
    message(FATAL_ERROR "GSL not found") 
endif(NOT GSL_LIBRARY) 

add_executable(
    cpp-binaries 
    "main.cpp" 
) 
+0

我對'GSL'不熟悉,但是您確定頭文件末尾沒有'.h'嗎?否則不要使用編譯器來查找頭文件,使用CMake模塊(在你的情況下['FindGSL'](https://cmake.org/cmake/help/latest/module/FindGSL.html))或['find_file ()'](https://cmake.org/cmake/help/latest/command/find_file.html)命令。或者嘗試先設置(CMAKE_REQUIRED_INCLUDES「/ usr/local/include」)。 – Florian

+0

[GSL](https://github.com/Microsoft/GSL)是僅包含標題的庫,並且沒有.h。設置'CMAKE_REQUIRED_INCLUDES'後,它也無法工作 –

回答

0

好失敗我看起來更成CheckIncludeFileCXX和你基本上指定與CMAKE_REQUIRED_INCLUDES東西,否則它不知道到哪裏去尋找。爲了給它一些東西,它悄悄地搜索與find_path包括,但仍然錯誤,如果沒有發現。

project(gsl_t) 
cmake_minimum_required(VERSION 3.2) 

find_path(
    gsl_location 
    gsl 
    HINTS ENV GSLDIR 
) 

if(gsl_location) 
    get_filename_component(gsl_include_dir ${gsl_location} DIRECTORY) 
    list(APPEND CMAKE_INCLUDE_PATH ${gsl_include_dir}) 
endif(gsl_location) 

include(CheckIncludeFileCXX) 
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH}) 
CHECK_INCLUDE_FILE_CXX("gsl/gsl" gsl_found) 

if(NOT gsl_found) 
    message(FATAL_ERROR "GSL not found. \ 
         Try setting the GSLDIR environment variable") 
endif(NOT gsl_found) 

add_executable(
    gsl_t 
    "main.cpp" 
)