Solved Using libc++ in FreeBSD 10

Has anyone used libc++ successfully in FreeBSD 10?

I'm working on a project where I recently decided to use the C++11 implementation of smart pointers, which requires LLVM's libc++ library on FreeBSD. After failing to get libc++ to work on my FreeBSD 9.1 system following the instructions at http://lists.freebsd.org/pipermail/freebsd-stable/2012-May/067645.html, I installed the May 15 snapshot of FreeBSD 10 since it is supposed to be built (or rather still being built) on the new C++ stack described at https://wiki.freebsd.org/NewC++Stack. Unfortunately, I'm getting linker errors because apparently libstdc++ is still getting tied up with my code.

For building the software, I'm using scons, and clang++ is being used for compiling the code. The build environment is set up in the sconstruct file as so:
Code:
env = Environment(PREFIX = GetOption('prefix'), CXX='clang++', CPPFLAGS='-g -std=c++11 -stdlib=libc++')

Above, scons is told to use clang++ for compiling the C++ code, the C++11 standard, and the libc++ standard library. I get pages full of errors similar to the error shown below:
Code:
undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'

I even have /etc/libmap.conf with the following entry:
Code:
libsupc++.so.1  libcxxrt.so

If I remove the flags for using C++11 and libc++ from my sconstruct file, the code compiles successfully (I haven't added any C++11 features to my code, yet). When I run ldd -a on the finished executable, I'm seeing entries for libstdc++ associated with libraries like Boost:
Code:
/usr/local/lib/libboost_thread.so.5:
        libboost_system.so.5 => /usr/local/lib/libboost_system.so.5 (0x2860d000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x283af000)
        libm.so.5 => /lib/libm.so.5 (0x28498000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x284b5000)
        libthr.so.3 => /lib/libthr.so.3 (0x28610000)
        libc.so.7 => /lib/libc.so.7 (0x284c0000)

I'm fairly certain I used libc++ when building and installing the ports for Boost. Why would libstdc++ be associated with Boost on my system? I even made sure to add the following to my /etc/make.conf before installing any ports on my FreeBSD 10 system:
Code:
CC=clang
CXX=clang++
CPP=clang-cpp
WITH_LIBCPLUSPLUS=yes

Can anyone tell me how I might be able to remove any dependencies in my code for libstdc++? Or how can I use libstdc++ and libc++ together successfully? What might I be doing wrong?

Any help on this would be greatly appreciated. If I can't get libc++ to work in FreeBSD in the next few days, unfortunately, I'm going to have to go back to a GNU/Linux-based distribution for my system. I really don't want to give up on FreeBSD because of this one issue, but this one issue is definitely a show-stopper.
 
For c++11 support, I installed lang/gcc. This was gcc 4.6 and allowed me to use all of the new functionality I required. Just make sure to include /usr/local/lib/gcc46 in your LD_LIBRARY_PATH.

Also, note that most C++ compilers have supported the newer smart pointers for a long long time, just under the tr1 namespace.

Code:
#include <tr1/memory>
...
std::tr1::shared_ptr<SomeClass> someClass;
 
I don't know how SCONS works, but clang and c++11 support in FreeBSD 9-STABLE is fine. For cmake the following configuration is enough.
Code:
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -stdlib=libc++")

Code:
/opt/bin/mous-ncurses:
        libMousCore.so => /opt/lib/libMousCore.so (0x8008e4000)
        libncursesw.so.8 => /lib/libncursesw.so.8 (0x800b04000)
        libiconv.so.3 => /usr/local/lib/libiconv.so.3 (0x800d59000)
        libc++.so.1 => /usr/lib/libc++.so.1 (0x801052000)
        libm.so.5 => /lib/libm.so.5 (0x801309000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801528000)
        libthr.so.3 => /lib/libthr.so.3 (0x801735000)
        libc.so.7 => /lib/libc.so.7 (0x801957000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x801ca6000)
 
I believe the Boost libraries port was forcing the use of libstdc++ in its build, hence the linker errors.

I hate to say it, but after giving my programming interest priority over my interest in FreeBSD, shortly after experiencing these linker errors, I switched to Fedora 18 for a while. I know, "Boo! Hiss!" :p But I never enjoyed Fedora as much as I enjoyed FreeBSD.

Now I'm glad to say that I've recently installed FreeBSD 10 as my desktop system of choice, and the linker errors are no more (they have ceased to be!). I suppose the differences would be:

  • This is a production release, as opposed to the pre-release snapshot I installed last year.
  • The Boost libraries port is newer.
  • There are no signs of libstdc++ on my system (Hooray for libc++!).
This thread can be marked as SOLVED. Thank you to everyone who provided input.
 
Statically linking boost libraries could help (perhaps). To avoid boost dependencies you must compile your own copy of boost libraries with static linking of dependencies, then link your program against the already compiled (static or dynamic) boost libraries. I downloaded the archive from the boost web site and compiled it with my options. It works from what I have seen (system, filesystem, regexp, and very few others).
 
Back
Top