How to compile/link Boost with clang++/libc++?
Asked Answered
M

2

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

Million answered 13/12, 2011 at 8:14 Comment(0)
D
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.

Dymphia answered 13/12, 2011 at 23:22 Comment(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.Preeminence
Is it just boost::signal not getting built? I think I am missing a lot of variants when build completeAllergen
nevermind. i think the bootstrap for boost wasn't finding iconv for some reason and cause it not build some of my boost variantAllergen
This saved my day! It compiles fine with no warnings latest Boost 1.62 with Apple LLVM ver 7.0.2.Sickening
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.Dietz
On Windows, the toolset is clang-winLonginus
M
14

Another option is to use Homebrew:

brew install boost --c++11

To get information on all options use:

brew info boost
Madel answered 3/9, 2013 at 9:13 Comment(5)
Does this link against libc++ instead of libstdc++?Carburize
if clang is available it links with libc++.Madel
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!Digress
Related lines in brew's boost formula - github.com/Homebrew/homebrew/blob/c77a584/Library/Formula/…Swipe
Does this have boost::mpl?Sacramental

© 2022 - 2024 — McMap. All rights reserved.