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
Author by
x-x
Updated on July 10, 2020Comments
-
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 about 12 yearsJust 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 about 12 yearsIs it just boost::signal not getting built? I think I am missing a lot of variants when build complete
-
Negative Zero about 12 yearsnevermind. 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 almost 10 yearsDoes this link against
libc++
instead oflibstdc++
? -
Jonas K almost 10 yearsif clang is available it links with libc++.
-
Stéphane about 9 yearsI 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 about 8 yearsRelated lines in brew's boost formula - github.com/Homebrew/homebrew/blob/c77a584/Library/Formula/…
-
The Vivandiere almost 8 yearsDoes this have
boost::mpl
? -
vsoftco over 7 yearsThis saved my day! It compiles fine with no warnings latest Boost 1.62 with Apple LLVM ver 7.0.2.
-
TemplateRex over 7 yearsNote that depending on one's system, one might also need to explicitly use
update-alternatives
to configure aliases forclang++
(otherwiseb2
can't find the proper toolset). The packages from apt.llvm.org don't set these aliases automatically. -
tim_hutton over 4 yearsOn Windows, the toolset is
clang-win