简体   繁体   English

CMake无法找到boost_test

[英]CMake unable to find boost_test

On OSX, I have installed Boost using brew install boost , and I'm trying to link as follows: 在OSX上,我使用brew install boost安装了Boost,我正在尝试链接如下:

cmake_minimum_required(VERSION 3.13)
project(LinkBoost)

set(CMAKE_CXX_STANDARD 14)

add_executable(LinkBoost
    desmond.cpp
    desmond.h
    integration.cpp
    integration.h
    main.cpp
    main.h
    utillity.cpp
    utillity.h)

list(APPEND CMAKE_PREFIX_PATH "/usr/local/Cellar/boost/1.69.0_2")
set(Boost_ADDITIONAL_VERSIONS "1.69.0" "1.69")

find_package(BoostCOMPONENTS filesystem system test REQUIRED)

target_include_directories(LinkBoost PUBLIC ".")

# adds include directories, definitions and link libraries
target_link_libraries(VelocityDispersion PUBLIC
        Boost::filesystem Boost::system Boost::test)

This however gives me: 然而,这给了我:

Unable to find the requested Boost libraries.

Boost version: 1.69.0

Boost include path: /usr/local/Cellar/boost/1.69.0_2/include

Could not find the following Boost libraries:

      boost_test

Some (but not all) of the required Boost libraries were found.  You may
need to install these additional Boost libraries.  Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.

Can anyone help me understand what is going wrong here? 任何人都可以帮我理解这里出了什么问题吗? I feel like it's something obvious that I'm missing... 我觉得这很明显,我很想念......

I've managed to get it working with something along the lines of: 我已经成功地使用了以下内容:

cmake_minimum_required(VERSION 3.13)
project(LinkBoost)

set(CMAKE_CXX_STANDARD 14)

FIND_PACKAGE(Boost COMPONENTS system filesystem unit_test_framework REQUIRED )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
LINK_DIRECTORIES ( ${Boost_LIBRARY_DIRS} )

add_executable(LinkBoost
    desmond.cpp
    desmond.h
    integration.cpp
    integration.h
    main.cpp
    main.h
    utillity.cpp
    utillity.h)

TARGET_LINK_LIBRARIES(LinkBoost LINK_PUBLIC
    ${Boost_LIBRARIES}
    ${Boost_FILESYSTEM_LIBRARY}
    ${Boost_SYSTEM_LIBRARY}
    ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

But I think a larger part of the problem was my fundamental understanding of how Boost Tests work - I would encourage anyone struggling here to read the documentation for Boost. 但我认为问题的一大部分是我对Boost Tests如何工作的基本理解 - 我会鼓励任何在这里努力阅读Boost文档的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM