为什么Cmake无法使用include_directories找到库?

时间:2017-05-31 19:36:23

标签: c++ cmake visual-studio-2017 cmake-gui

我正在尝试在CMake中为Visual Studio 2017配置一个项目,并给我一个错误:microhttpd NOT found这是配置它时唯一的问题,我尝试将标志关闭并运行。我把这两行包括在内:

include_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/include)

我有包含的microhttpd.h和lib文件夹中的libmicrohttpd.lib。如何正确调整以下代码才能找到它(在CmakeLists.txt中查找此库的部分):

include_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/includes)

option(MICROHTTPD_REQUIRED "Enable or disable the requirement of microhttp (http deamon)" ON)
find_library(MHTD NAMES microhttpd)
if("${MHTD}" STREQUAL "MHTD-NOTFOUND")
    if(MICROHTTPD_REQUIRED)
        message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_REQUIRED=OFF` to build without http deamon support")
    else()
        message(STATUS "microhttpd NOT found: disable http server")
        add_definitions("-DCONF_NO_HTTPD")
    endif()
else()
    set(LIBS ${LIBS} ${MHTD})
endif()

我是否需要使用include_directories以外的其他功能?

1 个答案:

答案 0 :(得分:1)

应该是:

find_library(MHTD microhttpd "path/to/the/lib")

第二个参数是库文件名。第三个是图书馆所在的路径。