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

2020-01-24 10:48发布

问题:

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

回答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.



回答2:

Another option is to use Homebrew:

brew install boost --c++11

To get information on all options use:

brew info boost