如何在OS X上轻松安装clang with brew来设置boost

How to set up boost easily with clang with brew installation on OS X

本文关键字:with clang brew boost 设置 安装 OS      更新时间:2023-10-16

我在OS X上通过brew安装了boost 1.60,El Capitan 10.11.4

> brew install boost
==> Downloading https://homebrew.bintray.com/bottles/boost-1.60.0_1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring boost-1.60.0_1.el_capitan.bottle.tar.gz
    /usr/local/Cellar/boost/1.60.0_1: 11,139 files, 436.0M

然而,在我的clang工具链中使用<boost/...>并不容易。它根本找不到boost目录。

> make
Scanning dependencies of target foo
[ 50%] Building CXX object CMakeFiles/foo.dir/foo.cpp.o
foo.cpp:16:10: fatal error: 'boost/type_index.hpp' file not found
#include <boost/type_index.hpp>
         ^
1 error generated.

我知道我必须设置一些环境变量或添加-I。但我想看看解决这个问题的最佳方法。

根据描述,我认为您的问题有两种可能的解决方案

  1. 在本地某个地方安装boost,并将boost_ROOT变量设置到该文件夹中。

  2. 将boost的include和libraries变量更新到相应的boost brew目录中。

以下是您需要添加到CMakeLists.txt 的代码段

set(Boost_NO_SYSTEM_PATHS TRUE)
if (Boost_NO_SYSTEM_PATHS)
  set(BOOST_ROOT "${ROOT_DIR}/")
  set(BOOST_INCLUDE_DIRS "${ROOT_DIR}/include")
  set(BOOST_LIBRARY_DIRS "${ROOT_DIR}/lib")
endif (Boost_NO_SYSTEM_PATHS)