Jan
20
GCC 4.7.0 on Ubuntu 10.10
I needed to have gcc 4.6+ on my laptop to compile some c++11 code, which my gcc 4.4.4 from synaptic wasn’t able to handle. Yes, yes ‘update your ubuntu’ is the default warcry in such situations, but I didn’t want that to happen, not yet. So I needed a second gcc in my system. This is a reminder post to myself, nothing spectacular, it’s a bit dirty as well, and it’s already thoroughly documented here http://gcc.gnu.org/faq.html#multiple
What I did was, checked out the latest gcc from svn. Configured it with ./configure –prefix=/usr/local/gcc-4.7.0 –program-suffix=-4.7.0 (btw that suffix is completely unnecessary because all files will anyway be dumped in a folder named gcc-4.7.0) and than called make -j10 (yes I went out, grabbed some food, a coffee, got back and it at that very second it was done). make install finally to install it into /usr/local/gcc-4.7.0/
Additionally I’ve overridden the existing symlinks to let me use the new gcc as default gcc:
ln -s /usr/local/gcc-4.7.0/bin/g++-4.7.0 /usr/bin/g++ -f
ln -s /usr/local/gcc-4.7.0/bin/gcc-4.7.0 /usr/bin/gcc -f
And one last thing, for programs compiled with 4.7.0 you need to tie in the new libstdc++ as well, otherwise you’ll get an expected error message when executing them. Each libstdc++ covers all previous versions, but cannot cover future versions. For example, with my gcc 4.4.4 from synaptic the libstdc++ version was: 6.0.7. The new gcc 4.7.0 comes with libstdc++ 6.0.14.
Just like the gcc and g++ a symlink for libstdc++ exists in /usr/lib. We need to override that one as well:
ln -s /usr/lib/libstdc++.so.6 libstdc++.so.6.0.14 -f
And that’s it. Of course, there are some other libs like the one for objective c etc. that need to be symlinked. OR you can make your own shell script that sets LD and exe paths accordingly, and while working in that context, you can use the selected gcc version. I will try this out, and add it to this post, one day .. soon?