2010-06-18 CPlusPlus0X

Getting a tool chain to experiment with

To experiment with the new C++ features it is good to have a tool chain so that you can see whether your code is OK. It is fun to write code but it is even better when you can run it!

Fortunately we have gcc. Unfortunately the support for the upcoming standard isn't in the stable releases. It wouldn't be an upcoming standard if it was I guess. So we need to get a development version. That isn't so hard to do (if you are on a linux/unix system that is)

The gcc development version can be downloaded. It is under version control using subversion. So it can be checked out. This way it is easy to update when the developers off gcc adds new features. Check it out like this:

svn checkout svn://gcc.gnu.org/svn/gcc/trunk <your-working-dir>

After that it is actually just a matter of running configure and make. I choose to set the prefix to my $HOME so that it would not mess with stable release of gcc I use for normal work. This installation is just for trying out the new features. So cd to your <your-working-dir> and follow the install instructions there. Configuring the build should be as easy as creating a build directory and doing

../configure --prefix=$HOME --enable-languages=c++

and building it should need no more than...

make install

should do it. gcc is then available in $HOME/bin. Voilá, we are read for trying out some code. Just one last thing to look out for. The new features are not activated by default in the beta version of gcc. So in order to use them we need to explicitly tell the compiler we want the new features. You can do like this:

$HOME/bin/gcc -static -std=c++0x

I have added the flag -static there as well to get statically linked executables. This way we avoid having to bother about dynamic linkage when running the programs. Remember we are using a version of gcc where the libraries are not installed in the standard location.