我正在尝试在CMake中为Visual Studio 2017配置项目,并给我错误:microhttpd NOT found这是配置它时的唯一问题,我尝试将其关闭并正常工作。我包括以下两行:

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

我在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以外的其他功能吗?

最佳答案

它应该是:

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

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

08-16 09:25