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

Community
  • 1
  • 1
x-x
  • 7,287
  • 9
  • 51
  • 78

2 Answers2

106

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.

Chris Chiasson
  • 547
  • 8
  • 17
Howard Hinnant
  • 206,506
  • 52
  • 449
  • 577
  • Just to add, boost::signals2 (`#include `) has a similar API to boost::signal and is header only, so not being able to build signals may not be so bad. – Chris Devereux Apr 01 '12 at 23:58
  • Is it just boost::signal not getting built? I think I am missing a lot of variants when build complete – Negative Zero Apr 28 '12 at 00: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 – Negative Zero Apr 28 '12 at 03:07
  • This saved my day! It compiles fine with no warnings latest Boost 1.62 with Apple LLVM ver 7.0.2. – vsoftco Oct 03 '16 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](http://apt.llvm.org) don't set these aliases automatically. – TemplateRex Oct 09 '16 at 10:00
  • On Windows, the toolset is ```clang-win``` – tim_hutton Jan 28 '20 at 13:08
14

Another option is to use Homebrew:

brew install boost --c++11

To get information on all options use:

brew info boost
Community
  • 1
  • 1
Jonas K
  • 4,215
  • 2
  • 24
  • 25