在 Mac El Capitan 上,Boost 不再与 Homebrew 一起使用

Boost no longer works with Homebrew on Mac El Capitan

我刚刚从 Yosemite 更新到 El Capitan,它破坏了我的一个依赖 Boost 的 C++ 程序。每当我尝试编译时,我都会收到这些错误:

fatal error: 'boost/timer/timer.hpp' file not found
#include <boost/timer/timer.hpp>

fatal error: 'boost/program_options.hpp' file not found
#include "boost/program_options.hpp"

我一直在用正确的标志编译它并且它之前工作得很好:

-lboost_timer-mt \
-lboost_program_options-mt \

我已经按照自制软件的说明进行了 chown /usr/local、运行 brew doctor 和 brew update,甚至 brew reinstall boost。我也检查过 timer.hpp 存在于 /usr/local/include/boost.

更新 运行: clang++ -E -x c++ - -v < /dev/null

Apple LLVM version 7.0.0 (clang-700.0.72) Target: x86_64-apple-darwin15.0.0 Thread model: posix  "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
    -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.2 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0
    -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
    -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /usr/local/lib -ferror-limit 19 -fmessage-length 272 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.11.0
    -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ - clang -cc1 version 7.0.0 based upon LLVM 3.7.0svn default target x86_64-apple-darwin15.0.0 ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/v1" ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/local/include" ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/Library/Frameworks"
    #include "..." search starts here:
    #include <...> search starts here:  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks (framework directory) End of search list.
    # 1 "<stdin>"
    # 1 "<built-in>" 1
    # 1 "<built-in>" 3
    # 332 "<built-in>" 3
    # 1 "<command line>" 1
    # 1 "<built-in>" 2
    # 1 "<stdin>" 2

我升级到 El Capitan 时遇到了同样的问题。我用 brew 重新安装 Boost 解决了这个问题。

如果你没有安装brew,你可以用

安装它
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

然后,安装 boost

brew install boost

您应该使用 xcode-select --install 安装 Xcode 命令行工具,以获得默认搜索 /usr/local 的 clang 版本。否则,您使用的是 Xcode 提供的版本,它只搜索 OS X SDK 路径。 (/usr/bin/gcc 和 /usr/bin/g++ 都调用 clang 而不是 gcc 的实际版本。)