C++ 如何使用 clang++/libc++ 编译/链接 Boost?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8486077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:39:31  来源:igfitidea点击:

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

c++boostclanglibc++

提问by x-x

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++."

这个问题的答案Why can't clang with libc++ in c++0x mode link this boost::program_options example?声明“您需要使用 clang++ -stdlib=libc++ 重建 boost。”

I'm using MacOS Lion with clang v3.0. How do I build Boost v1.48.0 using clang and link it with libc++?

我正在使用 MacOS Lion 和 clang v3.0。如何使用 clang 构建 Boost v1.48.0 并将其与 libc++ 链接?

Update: I've created a user-config.jamfile with the following:

更新:我创建了一个user-config.jam文件,内容如下:

using clang-darwin

...which will build Boost with clang instead of gcc. How do I link with libc++ instead of libstdc++?

...这将使用 clang 而不是 gcc 构建 Boost。如何链接 libc++ 而不是 libstdc++?

回答by Howard Hinnant

I didn't know how to do this either. But after poking around in here, the getting started, and trialand 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 thinkit works.

你会收到很多警告。由于LWG 2059,信号库将无法构建。但除此之外,我认为它有效。

回答by Jonas K

Another option is to use Homebrew:

另一种选择是使用Homebrew

brew install boost --c++11

To get information on all options use:

要获取有关所有选项的信息,请使用:

brew info boost