Jürgen Simon | 20 Jun 12:19 2012
Picon

Problems building Boost with clang toolchain and C++11

Hi,

I'm required to compile Boost with clang on OSX and C++11 support. I have
used the following commands to  attempt a build:

./bootstrap.sh -toolchain=clang
 ./bjam toolset=clang cxxflags="-std=c++0x11stdlib=libc++" threading=multi
variant=release link=shared runtime-link=shared --layout=system
--without-mpi --without-python --universal install --prefix=/opt/local

I'm getting errors from the linker:

clang-darwin.link.dll
bin.v2/libs/program_options/build/clang-darwin-4.2.1/release/threading-multi/libboost_program_options.dylib
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits&lt;char>,
std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced
from:

boost::program_options::invalid_syntax::get_template(boost::program_options::invalid_syntax::kind_t)
in cmdline.o
      boost::program_options::detail::cmdline::check_style(int) const in
cmdline.o
      boost::program_options::detail::cmdline::run() in cmdline.o

boost::program_options::detail::cmdline::parse_long_option(std::__1::vector<std::__1::basic_string&lt;char,
std::__1::char_traits&lt;char>, std::__1::allocator<char> >,
std::__1::allocator<std::__1::basic_string&lt;char,
std::__1::char_traits&lt;char>, std::__1::allocator<char> > > >&) in
cmdline.o
(Continue reading)

Abe | 20 Jun 19:03 2012
Picon

Re: Problems building Boost with clang toolchain and C++11

On Wed, Jun 20, 2012 at 5:19 AM, Jürgen Simon <juergen_simon <at> mac.com> wrote:

> I'm required to compile Boost with clang on OSX and C++11 support. I have
> used the following commands to  attempt a build:

> ./bootstrap.sh -toolchain=clang
>  ./bjam toolset=clang cxxflags="-std=c++0x11stdlib=libc++" threading=multi
> variant=release link=shared runtime-link=shared --layout=system
> --without-mpi --without-python --universal install --prefix=/opt/local

It looks like you have a typo:  "-std=c++0x11stdlib=libc++" should
probably be either "-std=c++0x -stdlib=libc++" or "-std=c++11
-stdlib=libc++", depending on compiler version.

For not-very-recent compiler versions [both GCC & Clang], IMO you
should use "-std=c++0x".  Recent versions [4.7.x, at least] of GCC
also accept "-std=c++11" -- and this produces exactly the same effect
as "-std=c++0x", AFAIK, except that your build scripts won`t be
backwards-compatible to e.g. GCC 4.5.x.

It seems that the latest release of Clang supports "-std=c++11" too:

  http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_31/final/include/clang/Frontend/LangStandards.def

Also FYI, even though I don`t recommend it:  old-ish versions of GCC
[and maybe Clang too] also support "gnu++0x", which means C++0x with
GNU extensions, and current releases of both compilers support both
that and "gnu++11", which probably means the same thing but might be
closer to the real C++2011 release [rather than using some obsolete
things from the pre-standard C++0x].
(Continue reading)

Marshall Clow | 20 Jun 20:05 2012
Picon

Re: Problems building Boost with clang toolchain and C++11


On Jun 20, 2012, at 10:03 AM, Abe wrote:

> On Wed, Jun 20, 2012 at 5:19 AM, Jürgen Simon <juergen_simon <at> mac.com> wrote:
> 
>> I'm required to compile Boost with clang on OSX and C++11 support. I have
>> used the following commands to  attempt a build:
> 
>> ./bootstrap.sh -toolchain=clang
>>  ./bjam toolset=clang cxxflags="-std=c++0x11stdlib=libc++" threading=multi
>> variant=release link=shared runtime-link=shared --layout=system
>> --without-mpi --without-python --universal install --prefix=/opt/local
> 
> 
> It looks like you have a typo:  "-std=c++0x11stdlib=libc++" should
> probably be either "-std=c++0x -stdlib=libc++" or "-std=c++11
> -stdlib=libc++", depending on compiler version.

Ok. I've looked into this a bit, and it appears to me that the problem is that the "-stdlib=libc++" is not
getting passed to the linker, so it's trying to link with libstdc++.

This works for me:
	../../../b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" 

-- Marshall

Marshall Clow     Idio Software   <mailto:mclow.lists <at> gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki
(Continue reading)

Marshall Clow | 20 Jun 20:10 2012
Picon

Re: Problems building Boost with clang toolchain and C++11

On Jun 20, 2012, at 11:05 AM, Marshall Clow wrote:
> On Jun 20, 2012, at 10:03 AM, Abe wrote:
> 
>> On Wed, Jun 20, 2012 at 5:19 AM, Jürgen Simon <juergen_simon <at> mac.com> wrote:
>> 
>>> I'm required to compile Boost with clang on OSX and C++11 support. I have
>>> used the following commands to  attempt a build:
>> 
>>> ./bootstrap.sh -toolchain=clang
>>> ./bjam toolset=clang cxxflags="-std=c++0x11stdlib=libc++" threading=multi
>>> variant=release link=shared runtime-link=shared --layout=system
>>> --without-mpi --without-python --universal install --prefix=/opt/local
>> 
>> 
>> It looks like you have a typo:  "-std=c++0x11stdlib=libc++" should
>> probably be either "-std=c++0x -stdlib=libc++" or "-std=c++11
>> -stdlib=libc++", depending on compiler version.
> 
> 
> Ok. I've looked into this a bit, and it appears to me that the problem is that the "-stdlib=libc++" is not
getting passed to the linker, so it's trying to link with libstdc++.
> 
> This works for me:
> 	../../../b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" 

I forgot to credit Howard Hinnant, who did some (most?) of the investigation here.
Shame on me.

-- Marshall

(Continue reading)

Jürgen Simon | 21 Jun 21:07 2012
Picon

Re: Problems building Boost with clang toolchain and C++11

Hello,

although the line copied into here was garbled, it was not a typo. I had the right flags but I was missing
linkflags. I managed to compile Boost with this. Now I got gtest acting up, but that's a different matter.

Thanks, fellas!

On 20.06.2012, at 19:03, Abe wrote:

> On Wed, Jun 20, 2012 at 5:19 AM, Jürgen Simon <juergen_simon <at> mac.com> wrote:
> 
>> I'm required to compile Boost with clang on OSX and C++11 support. I have
>> used the following commands to  attempt a build:
> 
>> ./bootstrap.sh -toolchain=clang
>>  ./bjam toolset=clang cxxflags="-std=c++0x11stdlib=libc++" threading=multi
>> variant=release link=shared runtime-link=shared --layout=system
>> --without-mpi --without-python --universal install --prefix=/opt/local
> 
> 
> It looks like you have a typo:  "-std=c++0x11stdlib=libc++" should
> probably be either "-std=c++0x -stdlib=libc++" or "-std=c++11
> -stdlib=libc++", depending on compiler version.
> 
> For not-very-recent compiler versions [both GCC & Clang], IMO you
> should use "-std=c++0x".  Recent versions [4.7.x, at least] of GCC
> also accept "-std=c++11" -- and this produces exactly the same effect
> as "-std=c++0x", AFAIK, except that your build scripts won`t be
> backwards-compatible to e.g. GCC 4.5.x.
> 
(Continue reading)


Gmane