为什么 Cmake 找不到使用 include_directories 的库?
Why can't Cmake find the library using include_directories?
我正在尝试在 CMake 中为 Visual Studio 2017 配置一个项目,但出现错误:microhttpd NOT found
这是配置它时唯一的问题,我尝试将其关闭并成功.我包括了这两行:
include_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/include)
我在 includes 中有 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")
第二个参数是库文件名。第三个是库所在的路径
我正在尝试在 CMake 中为 Visual Studio 2017 配置一个项目,但出现错误:microhttpd NOT found
这是配置它时唯一的问题,我尝试将其关闭并成功.我包括了这两行:
include_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/include)
我在 includes 中有 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")
第二个参数是库文件名。第三个是库所在的路径