Kirell
Kirell

Reputation: 9818

Compile boost C++11 clang mac cannot find cstddef

I cannot compile boost with clang 3.1 on Mac os x 10.8.2.

This is what I did:

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

I also tried without chrono, test, wave and signals. I tried a user-config.jam with

using clang-darwin

This is the error I have for almost every file:

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

It is kind of similar to How to compile/link Boost with clang++/libc++?

Thank you :-)

Update: I do have the latest Xcode 4.5.2 with the command line tools installed.

Here is part of the console output:

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.

Building the Boost C++ Libraries.

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

Component configuration:

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

Upvotes: 14

Views: 17995

Answers (3)

Alexander Larkin
Alexander Larkin

Reputation: 45

For Ubuntu 16.04, I'm able to build boost with c++11 using gcc:

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/

The command for building my program:

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

Before that the command was:

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

, but this old command (that worked before well with older OS and boost/etc) doesn't work anymore saying errors " undefined reference to boost::re_detail_106501 " (said by /tmp/cc0Zn8lo.o: In function `bool boost::regex_search...)

((also if I don't use "-I/usr/include/c++/5/ -I/usr/include/x86_64-linux-gnu/c++/5/" for ./b2, then the error is "cannot find cstddef" during building boost, so exactly the same like the subject of this ticket))

Upvotes: -3

Kirell
Kirell

Reputation: 9818

I finally fixed my problem after many hours.

Homebrew was messing with my path and for some reason my clang could not find the libc++ headers.

There is a bug is boost 1.52.

See Boost numeric limits bug

I had to edit the file :

boost/config/stdlib/libcpp.hpp

and patch it:

#if _LIBCPP_VERSION < 1002 
#   define BOOST_NO_CXX11_NUMERIC_LIMITS 
#endif 

Now boost is building properly ...

Upvotes: 4

servn
servn

Reputation: 3069

It looks like you forgot to install the libc++ headers alongside clang.

If you don't want to mess with installing the headers, try the version of clang distributed by Apple as part of the Command Line Tools package; it's been through more testing, and it's already set up properly.

Upvotes: 6

Related Questions