CMake 找不到 cpp-netlib 库
CMake can't find cpp-netlib libraries
我最近开始学习 CMake,并决定将它用于我正在处理的一个旧项目。该项目有 cpp-netlib、boost 和 Openssl 作为依赖项。
这是我想出的工作 CMakeLists.txt 文件。
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.1)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
PROJECT(MangaMe)
INCLUDE_DIRECTORIES(includes)
ADD_EXECUTABLE(mangaMe src/mangaMe.cpp)
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost 1.59.0 REQUIRED COMPONENTS system thread filesystem)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMe ${Boost_LIBRARIES})
SET(OPENSSL_LIB_DIR /usr/local/Cellar/openssl/1.0.2e/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/openssl/1.0.2e/include)
TARGET_LINK_LIBRARIES(mangaMe ${OPENSSL_LIB_DIR}/libcrypto.dylib ${OPENSSL_LIB_DIR}/libssl.dylib)
#WHY DOESNT THIS WORK!?!??!!?
#FIND_PACKAGE(cppnetlib 0.11 REQUIRED COMPONENTS client-connections server-parsers uri)
#INCLUDE_DIRECTORIES(${cppnetlib_INCLUDE_DIRS})
#TARGET_LINK_LIBRARIES(mangaMe ${cppnetlib_LIBRARIES})
SET(CPPNETLIB_LIB_DIR /usr/local/Cellar/cpp-netlib/0.11.2/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/cpp-netlib/0.11.2/include)
TARGET_LINK_LIBRARIES(mangaMe ${CPPNETLIB_LIB_DIR}/libcppnetlib-client-connections.a ${CPPNETLIB_LIB_DIR}/libcppnetlib-server-parsers.a ${CPPNETLIB_LIB_DIR}/libcppnetlib-uri.a)
我想知道是否有人知道为什么使用 FIND_PACKAGE 查找 cppnetlib 的注释部分不起作用?我使用自制软件安装 cpp-netlib,当我 运行 一个 if(cppnetlib_FOUND) 我知道它找到了包,但它似乎找不到库,所以当我尝试使我的项目出错时说它缺少 cpp-netlib 中的库。我还注意到,当我在 FIND_PACKAGE 中将版本设置为 0.11.2(当前安装的版本)时,我收到一条消息说
-- Boost version: 1.59.0
-- Found the following Boost libraries:
-- system
-- thread
-- filesystem
CMake Error at CMakeLists.txt:16 (FIND_PACKAGE):
Could not find a configuration file for package "cppnetlib" that is
compatible with requested version "0.11.2".
The following configuration files were considered but not accepted:
/usr/local/lib/cmake/cppnetlib/cppnetlibConfig.cmake, version: 0.11.1
/usr/local/lib/cmake/cppnetlib/cppnetlibConfig.cmake, version: 0.11.1
-- Configuring incomplete, errors occurred!
See also "/Users/LittleNewt/gitness/mangaMe/build/CMakeFiles/CMakeOutput.log".
没什么大不了的,因为当我明确指定目录时它会起作用,但我仍然想知道为什么我不能只使用 FIND_PACKAGE。
尝试将 cppnetlib_INCLUDE_DIRS
更改为 CPPNETLIB_INCLUDE_DIRS
,将 cppnetlib_LIBRARIES
更改为 CPPNETLIB_LIBRARIES
。
前缀不是包名称,而是包的 CMake 文件中导出的内容。这是使用大写字母的来源:https://github.com/cpp-netlib/cpp-netlib/blob/master/cppnetlibConfig.cmake.in
我最近开始学习 CMake,并决定将它用于我正在处理的一个旧项目。该项目有 cpp-netlib、boost 和 Openssl 作为依赖项。 这是我想出的工作 CMakeLists.txt 文件。
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.1)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
PROJECT(MangaMe)
INCLUDE_DIRECTORIES(includes)
ADD_EXECUTABLE(mangaMe src/mangaMe.cpp)
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost 1.59.0 REQUIRED COMPONENTS system thread filesystem)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMe ${Boost_LIBRARIES})
SET(OPENSSL_LIB_DIR /usr/local/Cellar/openssl/1.0.2e/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/openssl/1.0.2e/include)
TARGET_LINK_LIBRARIES(mangaMe ${OPENSSL_LIB_DIR}/libcrypto.dylib ${OPENSSL_LIB_DIR}/libssl.dylib)
#WHY DOESNT THIS WORK!?!??!!?
#FIND_PACKAGE(cppnetlib 0.11 REQUIRED COMPONENTS client-connections server-parsers uri)
#INCLUDE_DIRECTORIES(${cppnetlib_INCLUDE_DIRS})
#TARGET_LINK_LIBRARIES(mangaMe ${cppnetlib_LIBRARIES})
SET(CPPNETLIB_LIB_DIR /usr/local/Cellar/cpp-netlib/0.11.2/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/cpp-netlib/0.11.2/include)
TARGET_LINK_LIBRARIES(mangaMe ${CPPNETLIB_LIB_DIR}/libcppnetlib-client-connections.a ${CPPNETLIB_LIB_DIR}/libcppnetlib-server-parsers.a ${CPPNETLIB_LIB_DIR}/libcppnetlib-uri.a)
我想知道是否有人知道为什么使用 FIND_PACKAGE 查找 cppnetlib 的注释部分不起作用?我使用自制软件安装 cpp-netlib,当我 运行 一个 if(cppnetlib_FOUND) 我知道它找到了包,但它似乎找不到库,所以当我尝试使我的项目出错时说它缺少 cpp-netlib 中的库。我还注意到,当我在 FIND_PACKAGE 中将版本设置为 0.11.2(当前安装的版本)时,我收到一条消息说
-- Boost version: 1.59.0
-- Found the following Boost libraries:
-- system
-- thread
-- filesystem
CMake Error at CMakeLists.txt:16 (FIND_PACKAGE):
Could not find a configuration file for package "cppnetlib" that is
compatible with requested version "0.11.2".
The following configuration files were considered but not accepted:
/usr/local/lib/cmake/cppnetlib/cppnetlibConfig.cmake, version: 0.11.1
/usr/local/lib/cmake/cppnetlib/cppnetlibConfig.cmake, version: 0.11.1
-- Configuring incomplete, errors occurred!
See also "/Users/LittleNewt/gitness/mangaMe/build/CMakeFiles/CMakeOutput.log".
没什么大不了的,因为当我明确指定目录时它会起作用,但我仍然想知道为什么我不能只使用 FIND_PACKAGE。
尝试将 cppnetlib_INCLUDE_DIRS
更改为 CPPNETLIB_INCLUDE_DIRS
,将 cppnetlib_LIBRARIES
更改为 CPPNETLIB_LIBRARIES
。
前缀不是包名称,而是包的 CMake 文件中导出的内容。这是使用大写字母的来源:https://github.com/cpp-netlib/cpp-netlib/blob/master/cppnetlibConfig.cmake.in