首页 > 解决方案 > OSX(brew)上 BOOST_ROOT 和 BOOST_LIBRARY_DIR 的正确位置?

问题描述

我正在使用 CMake 构建,我收到错误 Boost can't be found。我在 brew 安装的 OSX 上使用 Boost 1.68.0。有人告诉我配置 CMakeList.txt 的最佳方法是设置BOOST_ROOTBOOST_LIBRARY_DIR. 请原谅我的无知,但是那些目录指的是哪些目录?

我猜他们是我猜到的其中之一。

losers-mbp:Cellar loser$ pwd
/usr/local/Cellar
losers-mbp:Cellar loser$ tree -L 3 boost/
boost/
└── 1.68.0          <--- Is this BOOST_ROOT?
    ├── INSTALL_RECEIPT.json
    ├── include
    │   └── boost   <--- Or is this BOOST_ROOT?
    │       ├── accumulators
    │       ├── algorithm
    │       ├── align
    │       ├── align.hpp
    │       ├── aligned_storage.hpp
    │       ... more source files
    └── lib                        <--- I'm guessing this is BOOST_LIBRARY_DIR
        ├── libboost_atomic-mt.a
        ├── libboost_atomic-mt.dylib
        ├── libboost_chrono-mt.a
        ├── libboost_chrono-mt.dylib
        ... more binaries

无论如何,我尝试使用此 CMake 文件进行构建:

# About this build.
project(webtest)
set(CMAKE_CXX_STANDARD 11)
cmake_minimum_required(VERSION 3.12)
# Tell me what I need.
find_package(Boost 1.68.0 COMPONENTS asio REQUIRED)
# Set paths info.
set(BOOST_INCLUDE_DIRS "/usr/local/Cellar/boost/1.68.0/include")
set(BOOST_LIBRARYDIR "/usr/local/Cellar/boost/1.68.0")
set(BOOST_ROOT "/usr/local/Cellar/boost/1.68.0/lib")
# Include things.
include_directories(${BOOST_INCLUDE_DIRS})
# Build it.
add_executable(webtest main.cpp)
target_link_libraries(webtest ${BOOST_LIBRARYDIR})

我得到的错误说我的包含路径是/usr/local/include当我特别告诉它查看 in 时/usr/local/Cellar/boost/1.68.0/include,所以它甚至没有查看我告诉它的位置。

CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.68.0

  Boost include path: /usr/local/include

  Could not find the following Boost libraries:

          boost_asio

  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.

对于BOOST_INCLUDE_DIRS,我也尝试了以下路径/usr/local/Cellar/boost/1.68.0/include/boost

我在这里做错了什么?

标签: c++boostcmake

解决方案


推荐阅读