How to compile/link Boost with clang++/libc++?

43,165

Solution 1

I didn't know how to do this either. But after poking around in here, the getting started, and trial and error:

$ ./bootstrap --with-toolset=clang
$ ./b2 clean
$ ./b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"

You'll get lots of warnings. And the signals library will fail to build due to LWG 2059. But otherwise I think it works.

Solution 2

Another option is to use Homebrew:

brew install boost --c++11

To get information on all options use:

brew info boost
Share:
43,165
x-x
Author by

x-x

Updated on July 10, 2020

Comments

  • x-x
    x-x almost 4 years

    The answer to this question Why can't clang with libc++ in c++0x mode link this boost::program_options example? states "You need to rebuild boost using clang++ -stdlib=libc++."

    I'm using MacOS Lion with clang v3.0. How do I build Boost v1.48.0 using clang and link it with libc++?

    Update: I've created a user-config.jam file with the following:

    using clang-darwin
    

    ...which will build Boost with clang instead of gcc. How do I link with libc++ instead of libstdc++?

  • Chris Devereux
    Chris Devereux about 12 years
    Just to add, boost::signals2 (#include <boost/signals2.hpp>) has a similar API to boost::signal and is header only, so not being able to build signals may not be so bad.
  • Negative Zero
    Negative Zero about 12 years
    Is it just boost::signal not getting built? I think I am missing a lot of variants when build complete
  • Negative Zero
    Negative Zero about 12 years
    nevermind. i think the bootstrap for boost wasn't finding iconv for some reason and cause it not build some of my boost variant
  • Theo Belaire
    Theo Belaire almost 10 years
    Does this link against libc++ instead of libstdc++?
  • Jonas K
    Jonas K almost 10 years
    if clang is available it links with libc++.
  • Stéphane
    Stéphane about 9 years
    I ran "brew install boost --c++11" followed by "otool -L /usr/local/Cellar/boost/1.57.0/lib/libboost_regex-mt.dylib" and can confirm that Boost is now linking against libc++. Thanks!
  • Marius
    Marius about 8 years
    Related lines in brew's boost formula - github.com/Homebrew/homebrew/blob/c77a584/Library/Formula/…
  • The Vivandiere
    The Vivandiere almost 8 years
    Does this have boost::mpl?
  • vsoftco
    vsoftco over 7 years
    This saved my day! It compiles fine with no warnings latest Boost 1.62 with Apple LLVM ver 7.0.2.
  • TemplateRex
    TemplateRex over 7 years
    Note that depending on one's system, one might also need to explicitly use update-alternatives to configure aliases for clang++ (otherwise b2 can't find the proper toolset). The packages from apt.llvm.org don't set these aliases automatically.
  • tim_hutton
    tim_hutton over 4 years
    On Windows, the toolset is clang-win