【问题标题】:CMake with Boost 1.62.0: "No Boost libraries were found"带有 Boost 1.62.0 的 CMake:“未找到 Boost 库”
【发布时间】:2016-11-30 17:03:35
【问题描述】:

使用以下CMake 代码:

cmake_minimum_required(VERSION 3.6)
project(TrustLineManager)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(BOOST_ROOT D:/Tools/boost_1_62_0/)

set(Boost_INCLUDE_DIRS D:/Tools/boost_1_62_0/boost)
set(Boost_LIBRARY_DIRS D:/Tools/boost_1_62_0/libs)

set(BOOST_INCLUDEDIR C:/MinGW/include)
set(BOOST_LIBRARYDIR C:/MinGW/lib)

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

find_package(Boost
        1.62.0
        COMPONENTS system
                   filesystem
        REQUIRED)

include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(TrustLineManager ${Boost_LIBRARIES})

我收到此错误:

Error:Unable to find the requested Boost libraries.
Boost version: 1.62.0
Boost include path: D:/Tools/boost_1_62_0
Could not find the following static Boost libraries:
        boost_system         boost_filesystem
No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.

我应该怎么做才能解决它?

编辑:

我将我的CMake 代码修改为:

cmake_minimum_required(VERSION 3.6)
project(TrustLineManager)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)

set(BOOST_ROOT "D:/Tools/boost_1_62_0")

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})

add_executable(TrustLineManager ${SOURCE_FILES})

target_link_libraries(TrustLineManager Boost::filesystem Boost::thread)

我现在有这个错误:

Error:Target "TrustLineManager" links to target "Boost::filesystem" but the target was not found.  Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?

这是Boost目录内容的截图:

【问题讨论】:

  • 为什么不按照错误消息中的说明进行操作?你确定 boost 的东西安装在C:\MinGW吗?
  • @πάντα ῥεῖ 导致 boost 目录不包含 forlders include 和 lib
  • 你有哪个 CMake 版本?如果它太旧,它的“FindBoost.cmake”将无法找到最新的 Boost 版本。我认为仅在 CMake 3.7(或者可能是 CMake 3.6.3)中引入了对 Boost 1.62 的支持。

标签: c++ boost cmake


【解决方案1】:

显然 CMake 找到了 Boost,因为它能够检测到它的版本 (1.62.0)。

CMake 使用文件FindBoost.cmake 来确定要链接的库。 当出现新的 boost 版本时,此文件会不断更新。 在那里,对 Boost 1.62.0 的支持仅适用于 CMake >= 3.7.0。

所以只需更新你的 CMake 版本(或只是文件 FindBoost.cmake),你会没事的。

【讨论】:

  • 我遇到了同样的问题,我有最新版本的 CMake (3.9.3)。我正在寻找 1.6.5,当我检查 FindBoost.cmake 时,我看到 1.6.5 在那里......不知道发生了什么。
猜你喜欢
  • 2018-06-04
  • 2014-01-06
  • 2011-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-02
  • 1970-01-01
相关资源
最近更新 更多