Solved Using libc++ in FreeBSD 10



Reaction score: 7
Messages: 61

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, 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 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:
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:
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:
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:
/usr/local/lib/ => /usr/local/lib/ (0x2860d000) => /usr/lib/ (0x283af000) => /lib/ (0x28498000) => /lib/ (0x284b5000) => /lib/ (0x28610000) => /lib/ (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:
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.



Reaction score: 554
Messages: 1,474

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.

#include <tr1/memory>
std::tr1::shared_ptr<SomeClass> someClass;


New Member

Reaction score: 2
Messages: 14

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.
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -stdlib=libc++")
/opt/bin/mous-ncurses: => /opt/lib/ (0x8008e4000) => /lib/ (0x800b04000) => /usr/local/lib/ (0x800d59000) => /usr/lib/ (0x801052000) => /lib/ (0x801309000) => /lib/ (0x801528000) => /lib/ (0x801735000) => /lib/ (0x801957000) => /lib/ (0x801ca6000)



Reaction score: 7
Messages: 61

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.


Well-Known Member

Reaction score: 32
Messages: 359

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).