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 ?
-
2http://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html – James May 09 '11 at 16:19
-
You've tagged this both C++ and C. Does the library contain C++ code? – Rup May 09 '11 at 16:34
-
Yes, although in separate libraries. Eg library1.a is c code . library2.a is cpp code. – Abhijith May 09 '11 at 16:37
-
Why don't you just recompile and stop worrying about this? – David Heffernan May 09 '11 at 16:51
1 Answers
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.

- 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
-
1Usually. 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