CMake 找不到 boost_test
Posted
技术标签:
【中文标题】CMake 找不到 boost_test【英文标题】:CMake unable to find boost_test 【发布时间】:2019-05-14 23:03:08 【问题描述】:在 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)
然而这给了我:
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.
谁能帮我理解这里出了什么问题?我觉得我错过了一些明显的东西......
【问题讨论】:
Boost.Test 框架有几个不同的usage variants。您能否验证 Boost.Test 库是否已安装在您的系统上,可能与其他libboost_
Boost 库一起安装,例如 libboost_system
、libboost_filesystem
等。
【参考方案1】:
我已经设法让它与以下内容一起工作:
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)
但我认为问题的很大一部分在于我对 Boost 测试如何工作的基本理解 - 我鼓励任何在这里苦苦挣扎的人阅读 Boost 文档。
【讨论】:
以上是关于CMake 找不到 boost_test的主要内容,如果未能解决你的问题,请参考以下文章