CMake with Boost 1.62.0:"没有找到Boost库"

时间:2016-11-30 17:03:35

标签: 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

1 个答案:

答案 0 :(得分:0)

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

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

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