CMake找不到cpp-netlib库

时间:2015-12-24 05:12:44

标签: c++ cmake cpp-netlib

我最近开始学习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时,它不是很有效。

1 个答案:

答案 0 :(得分:4)

尝试将cppnetlib_INCLUDE_DIRS更改为CPPNETLIB_INCLUDE_DIRS,将cppnetlib_LIBRARIES更改为CPPNETLIB_LIBRARIES

前缀不是通过包名称,而是通过包的CMake文件中导出的内容。以下是使用大写字母的来源:https://github.com/cpp-netlib/cpp-netlib/blob/master/cppnetlibConfig.cmake.in