71

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++?

2 Answers 2

107

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.

6
  • 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. Commented Apr 1, 2012 at 23:58
  • Is it just boost::signal not getting built? I think I am missing a lot of variants when build complete Commented Apr 28, 2012 at 0:37
  • nevermind. i think the bootstrap for boost wasn't finding iconv for some reason and cause it not build some of my boost variant Commented Apr 28, 2012 at 3:07
  • This saved my day! It compiles fine with no warnings latest Boost 1.62 with Apple LLVM ver 7.0.2.
    – vsoftco
    Commented Oct 3, 2016 at 17:27
  • 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. Commented Oct 9, 2016 at 10:00
14

Another option is to use Homebrew:

brew install boost --c++11

To get information on all options use:

brew info boost
5
  • 2
    Does this link against libc++ instead of libstdc++? Commented May 12, 2014 at 17:58
  • 1
    if clang is available it links with libc++.
    – Jonas K
    Commented May 20, 2014 at 15:50
  • 1
    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!
    – Stéphane
    Commented Apr 2, 2015 at 6:07
  • 2
    Related lines in brew's boost formula - github.com/Homebrew/homebrew/blob/c77a584/Library/Formula/…
    – Marius
    Commented Mar 21, 2016 at 9:46
  • Does this have boost::mpl? Commented Jun 19, 2016 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.