编译boost C++11 clang在mac上找不到cstddef。

14

我无法在Mac OS X 10.8.2上使用Clang 3.1编译Boost。

这是我所做的:

./bootstrap.sh --with-toolset=clang
./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++"

我也尝试了不使用chrono、test、wave和signals。我尝试了一个包含以下内容的user-config.jam文件:

using clang-darwin

我几乎每个文件都遇到了这个错误:

/boost/config/select_stdlib_config.hpp:18:12: fatal error: 'cstddef' file not found

这有点类似于如何使用clang++/libc++编译/链接Boost?

谢谢 :-)

更新: 我已经安装了最新的Xcode 4.5.2和命令行工具。

这是控制台输出的部分内容:

Kikohs:trunk kikohs$ ./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++"
Performing configuration checks

- 32-bit                   : no
- 64-bit                   : yes
- x86                      : yes
- has_icu builds           : no
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
    - gcc visibility           : yes
    - long double support      : no
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.

构建 Boost C++ 库。

- iconv (libc)             : no
- iconv (separate)         : yes
- icu                      : no
- icu (lib64)              : no

组件配置:

- atomic                   : building
- chrono                   : building
- context                  : building
- date_time                : building
- exception                : building
- filesystem               : building
- graph                    : building
- graph_parallel           : building
- iostreams                : building
- locale                   : building
- math                     : building
- mpi                      : building
- program_options          : building
- python                   : building
- random                   : building
- regex                    : building
- serialization            : building
- signals                  : building
- system                   : building
- test                     : building
- thread                   : building
- timer                    : building
- wave                     : building

...patience...
...patience...
...patience...
...patience...
...found 8672 targets...
...updating 1127 targets...
common.mkdir bin.v2/libs/atomic
common.mkdir bin.v2/libs/atomic/build
common.mkdir bin.v2/libs/atomic/build/clang-darwin-4.2.1
common.mkdir bin.v2/libs/atomic/build/clang-darwin-4.2.1/debug
clang-darwin.compile.c++ bin.v2/libs/atomic/build/clang-darwin-4.2.1/debug/lockpool.o
In file included from libs/atomic/src/lockpool.cpp:1:
./boost/atomic.hpp:10:10: fatal error: 'cstddef' file not found
#include <cstddef>
     ^
1 error generated.

"clang++" -x c++ -O0 -g -std=c++11 -stdlib=libc++ -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -DBOOST_ATOMIC_DYN_LINK=1 -DBOOST_ATOMIC_SOURCE -I"." -c -o "bin.v2/libs/atomic/build/clang-darwin-4.2.1/debug/lockpool.o" "libs/atomic/src/lockpool.cpp"

我已经更正了您的标题,将“cstddef.h”更改为“cstddef”。 - Keith Thompson
3个回答

6

看起来您忘记了在clang旁边安装libc++头文件。

如果您不想处理安装头文件的问题,请尝试由苹果作为命令行工具包的一部分分发的clang版本; 它经过更多测试,已经正确设置。


4

经过多个小时的努力,我终于解决了我的问题。

Homebrew 搞乱了我的路径,由于某些原因,我的 clang 找不到 libc++ 头文件。

boost 1.52 存在一个 bug。

请参见 Boost numeric limits bug

我不得不编辑这个文件:

boost/config/stdlib/libcpp.hpp

并进行补丁安装:

#if _LIBCPP_VERSION < 1002 
#   define BOOST_NO_CXX11_NUMERIC_LIMITS 
#endif 

现在Boost正在正确地构建...

Homebrew现在具有使用C++11构建boost的选项,boost已经被Homebrew打补丁了:-)。 - Kirell
只是一条注释,如果你正在同时构建 Boost 和项目,我不认为可以使用 Travis-CI 完成这个任务。如果有人找到了方法,请让我知道,但我认为由于 Travis-CI 的 Clang 版本太过陈旧,所以很难实现。 - LB--

-3

对于Ubuntu 16.04,我能够使用gcc构建支持c++11的boost库:

cd /home/user/install/boost/boost_1_54/

./bootstrap.sh --with-toolset=gcc

./b2 toolset=gcc cxxflags="-std=c++11 -I/usr/include/c++/5/ -I/usr/include/x86_64-linux-gnu/c++/5/"

mkdir ../2

./b2 install --prefix=../2/

构建我的程序的命令:

g++ -std=c++11 -O2 fprint.cpp -o fprint -I/home/user/install/boost/2/include/ -L/home/user/install/boost/2/lib/ -lboost_regex -lboost_program_options

之前的命令是:

g++ -std=c++11 fprint.cpp -o fprint -lboost_regex -lboost_program_options

但是这个旧命令(在旧操作系统和boost库中工作正常)不再起作用,会出现错误:

"undefined reference to boost::re_detail_106501" (由/tmp/cc0Zn8lo.o: In function `bool boost::regex_search...所述)

(如果我在./b2中不使用“-I/usr/include/c++/5/ -I/usr/include/x86_64-linux-gnu/c++/5/”,则在构建boost时会出现“无法找到cstddef”的错误,因此与此工单的主题完全相同)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接