Broken C++ compilation on Debian

13.07.2012 9:24

I've noticed lately an issue with GNU C++ compilation on a few machines running mostly Debian Squeeze. Mostly because each one also has a few cherry picked testing and backports packages installed over the basic Squeeze system.

The symptoms are that linking all C++ programs will fail with an error message like this:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.4.5/libstdc++.a(functexcept.o):
relocation R_X86_64_32 against `std::bad_typeid::~bad_typeid()' can not be used
when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/libstdc++.a: could not read symbols: Bad

This error points in a completely wrong direction though and made me loose a few hours in hunting down its true cause. So for future reference, here is what's really causing it.

For some reason, this symlink for the standard C++ library gets broken:

/usr/lib/gcc/x86_64-linux-gnu/4.4.5/ -> ../../../

It seems that GCC sees the broken link and quietly decides the dynamic version of libstdc++ isn't available and attempts to link programs with the static one, which fails. I'm not sure exactly which package upgrade breaks the link, but since I saw this on more than one machine I'm guessing it's a bug somewhere and not just some quirk specific to me.

Once you know it, the fix is simple:

$ cd /usr/lib/gcc/x86_64-linux-gnu/4.4.5
$ sudo ln -s ../../../x86_64-linux-gnu/
Posted by Tomaž | Categories: Code

Add a new comment

(No HTML tags allowed. Separate paragraphs with a blank line.)