missing some c++11 support for clang in FreeBSD
Dimitry Andric
dim at FreeBSD.org
Tue May 14 07:02:21 UTC 2013
On May 14, 2013, at 02:35, Alexander K. Beros <alex at 154cm.com> wrote:
> I have just started using clang (on FreeBSD 9.1 AMD64) and encountered a
> couple problems. I have worked around these points, but in case they
> represent something unintentional (as opposed to some error on my part while
> building from the port) I would like to mention them. I am using
>
> FreeBSD clang version 3.1 (branches/release_31 156863) 20120523
> Target: x86_64-unknown-freebsd9.0
> Thread model: posix
>
> A key element in solving both problems was the installation of gcc47. That
> was unexpected since I initially installed clang under the assumption that
> FBSD is moving from gcc to clang and since gcc42 doesn't support c++11.
On FreeBSD 9.1, you first need to build libc++, which provides C++11
support. (On 10.0-CURRENT, it is enabled and installed by default, but
not on previous releases.)
To build and install libc++ on 9.1, add the following lines to
/etc/src.conf:
CC=clang
CXX=clang++
CPP=clang-cpp
WITH_LIBCPLUSPLUS=foo
Then build and install world in the usual manner. If you prefer to only
build libc++ (and its support library, libcxxrt) manually, you can do
the following:
cd /usr/src/lib/libcxxrt
make obj && make depend && make
sudo make install
cd /usr/src/lib/libc++
make obj && make depend && make
sudo make install
After libc++ is installed, you still need to tell clang to use it
instead of GNU libstdc++; see below.
> 1..
> Symptom:
>
> %> clang++ -std=c++11 -stdlib=libstdc++ refparms.c++
> initListTest.cpp:43:10: fatal error: 'initializer_list' file not
> found
> #include <initializer_list>
>
> I had included initializer_list.
To enable libc++, you must add the flag -stdlib=libc++ instead. If you
use -stdlib=libstdc++, or no -stdlib option, it will use the base system
version of GNU libstdc++, which is the version that comes with gcc 4.2,
and does not support C++11.
> Temporary Solution:
> I built gcc47 from the port and then added the following to my
> .cshrc file
> alias clang11 'clang++ -std=c++11 -I/usr/local/lib/gcc47/include/c++
> -I/usr/local/lib/gcc47/include/c++/x86_64-portbld- freebsd9.1'
>
> Alternate solution, compile using g++47.
This will only work partially, since you still need to make sure to add
the proper flags during linking, so clang can find the libstdc++
libraries installed by the gcc47 port.
> 2..
> Symptom:
> /usr/lib/libstdc++.so.6: version GLIBCXX_3.4.14 required by
> /usr/home/../binaries/a.out not found
Yes, this is a problem with the gcc ports. They are basically unusable
for C++ as-is. Please complain to the maintainer. :-)
> Solution:
> I added the following line to /etc/libmap.conf
> libstdc++.so.6 gcc47/libstdc++.so.6
>
> again compiling with g++47 had no such problem.
This is a rather brute-force solution, but it should work, since newer
versions of libstdc++ are backwards compatible.
-Dimitry
More information about the freebsd-toolchain
mailing list