Howto: building and running c++0x apps on FreeBSD

Hi I'm doing some practice with c++0x and had troubles with FreeBSD 8.2 native gcc because it has too old version (4.2) that is not supporting c++0x at all.

clang works fine and I really liked it, but current port version (2.9) still not supporting lambdas, smartpointers etc :( That's why I write how to get a c++0x compiler on FreeBSD (I spent long time to find some tips about running this). First, let's install gcc 4.7

Code:
cd /usr/ports/lang/gcc47/
make install clean

After (moderate) long building you can notice it's installed with /usr/local prefifx. Now Makefile part of your project

Code:
CXX = g++47
DEBUG=-g
CXXFLAGS = -Wall -I /usr/local/lib/gcc47/include/ -std=c++0x $(DEBUG)
LDFLAGS = -L/usr/local/lib/gcc47 $(DEBUG)

Your app will built but not run because libstdc++.so.6 version mismatch:

Code:
/libexec/ld-elf.so.1: /usr/lib/libstdc++.so.6: version GLIBCXX_3.4.14 required by /usr/home/alt/.... not found

This is because dynaliking takes default /usr/lib/libstdc++.so.6 which is still used by native gcc4.2. So you should use freshly installed /usr/local/lib/gcc47/libstdc++.so.6 because it has requested version:

Code:
> strings /usr/local/lib/gcc47/libstdc++.so.6|grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
[B]GLIBCXX_3.4.14[/B]
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

Now the key thing: open /etc/libmap.conf file and put there this line
Code:
libstdc++.so.6 gcc47/libstdc++.so.6

P.S. Maybe it's not a very "howto" but this can help someone to solve problems with this.
 
An alternative would be to pass an extra option to the linker via the compiler flag -Wl,-rpath,/path_to_lib_dir which tells the runtime linker where to look for the shared libraries.
 
Back
Top