9

I have a static library that has been compiled with gcc 3.4.3 .I would like to use this in code that will now be compiled with gcc-4. I've read vaguely that gcc-3 and gcc-4 binaries are not compatible and that the library will need to be recompiled , but just want confirmation on this. Isn't there anyway a gcc-3 library can be used with gcc-4 ?

Abhijith
  • 2,592
  • 5
  • 18
  • 30

1 Answers1

3

Getting someone else in the organization, or at a vendor, to update their library to gcc 4 is not always an option, especially if they've abandoned it.

If C++: assuming that are able to link, at runtime you can blow up in C++ standard library template code that uses streams, as symbols generated by g++ 4 are resolved against definitions generated by g++ 3.

You might see this warning when linking:

/usr/bin/ld: warning: libstdc++.so.5, needed by (legacy static lib), may conflict with libstdc++.so.6

Here's an example you can get into: base class destructor ~basic_stringbuf() (actually a template) can be defined in your module compiled under g++ 3, which mistakenly gets called by the destructor ~basic_ostringstream() in libstdc++so.6, which is invoked by the g++ 4 compiled module. Ka-Boom.

I tried compat-libstdc++-33 but had no luck with that.

That said, I still link 32-bit gcc 3 era C libraries into my gcc 4.1.2 C++ programs.

Erik Olson
  • 1,154
  • 8
  • 18
  • It's actually a problem with name-mangling changes. C doesn't have these issues, so you can link against old C libraries. –  May 09 '11 at 20:05
  • 1
    Usually. Sometimes the C libraries change to the point where link works but code doesn't. Almost always this is due to macro expansion of getc and friends. – Joshua May 09 '11 at 20:07
  • However if the library is linked full static this will not be a problem. – Joshua May 09 '11 at 20:07
  • Very Useful comments , but the answer to the question varies i guess , depending on the scenario one would or would NOT be able to link to older libraries. – Abhijith May 10 '11 at 13:20