c++ - 带有 Boost 的 CMake 1.62.0 : "No Boost libraries were found"

标签 c++ boost cmake

使用以下 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 目录内容的屏幕截图:

enter image description here

最佳答案

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

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

因此,只需更新您的 CMake 版本(或仅更新文件 FindBoost.cmake)就可以了。

关于c++ - 带有 Boost 的 CMake 1.62.0 : "No Boost libraries were found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40894122/

相关文章:

c++ - 在某些情况下 CMake 找不到 Boost 的可能原因?

c++ - 如何在 CMake 中导入库

C 程序中带有默认参数的 C++ 头文件

c++ - 尽管链接到库,但未定义对函数的引用

c++ - 引用模板化类/对象的数据成员

c++ - 如何找出给定/安装的 Boost header 的版本?

elasticsearch - 在Elasticsearch中搜索词组时应用不同的 boost 值?

c++ - 共享内存段是否跨 boost 版本和编译器版本兼容

c++ - 涉及 `std::string` 的编译导致 Windows 错误状态

c++ - C/C++ 元程序的预处理