32

As far as I've understood, it is not possible to link libraries that use different versions of GCC's Application Binary Interface (ABI). Are there ABI changes to every version of GCC? Is it possible to link a library built with 4.3.1 if I use, say, GCC 4.3.2? Is there a matrix of some sort that lists all the ways I can combine GCC versions?

linuxbuild
  • 15,843
  • 6
  • 60
  • 87
Fredrik Ullner
  • 2,106
  • 2
  • 22
  • 28
  • 1
    It gets even better with GCC 5.1... Also see [Linking problems due to symbols with abi::cxx11?](http://stackoverflow.com/q/36159238) and [The Case of GCC-5.1 and the Two C++ ABIs](http://allanmcrae.com/2015/06/the-case-of-gcc-5-1-and-the-two-c-abis/). – jww Mar 22 '16 at 18:32

3 Answers3

22

Since gcc-3.4.0, the ABI is forward compatible. I.E. a library made using an older release can be linked with a newer one and it should work (the reverse doesn't). Obviously, there could be bugs, but there is only one mentionned in the documentation: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33678

AProgrammer
  • 51,233
  • 8
  • 91
  • 143
  • Could you please clarify the second sentence? If my shared dll is an older release but the executable a newer, it is fine, but if my shared dll is newer, and the executable older, it is not? – Cookie Nov 07 '12 at 12:35
  • @Cookie, right. And note that's for the compiler, the standard library has its own rules, but they also try to be forward compatible. – AProgrammer Nov 07 '12 at 12:45
  • 6
    It looks like its no longer forward compatible as of GCC 5.1. Also see [Linking problems due to symbols with abi::cxx11?](http://stackoverflow.com/q/36159238) and [The Case of GCC-5.1 and the Two C++ ABIs](http://allanmcrae.com/2015/06/the-case-of-gcc-5-1-and-the-two-c-abis/). – jww Mar 22 '16 at 18:37
  • 1
    I have had the same problem with GCC 5.2: I cannot link two libraries: one comes from a package of Ubuntu Wily, the other comes from a package of Intel Pin (which has been compiled with old version of gcc). – Ta Thanh Dinh Mar 24 '16 at 10:47
16

The official ABI page points to an ABIcheck. This tool may do, what you want.

linuxbuild
  • 15,843
  • 6
  • 60
  • 87
ablaeul
  • 2,750
  • 20
  • 22
  • 1
    Hm, the official ABI page has a code example (Multiple ABI Testing), where multiple versions are being used... How is this possible if they then say you should recompile everything with the same version? – Fredrik Ullner May 10 '10 at 12:34
  • 2
    That example shows how to use the linker in order to be able to link in multiple libraries. But they won't be interoperable: for example, you can't pass a vector from the first library to the other. – AProgrammer May 10 '10 at 13:18
  • 1
    I.e., it's relatively pointless since that's obviously something you would want to do. – Fredrik Ullner May 10 '10 at 13:25
  • @linuxbuild How to use it? Any example? – John Nov 07 '22 at 03:07
4

Ugh, yikes.
How can you tell which gcc compiled a given binary? Here is the death notice from gcc-4.7.2-1-mingw32.README.txt :

Binary incompatibility notice!

The C and C++ ABI changed in GCC 4.7.0, which means in general you can't link together binaries compiled with this version of the compiler and with versions before GCC 4.7.0. In particular:

  • The option -mms-bitfields is enabled by default, which means the bitfield layout follows the convention of the Microsoft compiler.

  • C++ class-member functions now follow the __thiscall calling convention.

  • The compiler now assumes that the caller pops the stack for the implicit arguments pointing to an aggregate return value. This affects functions returning structs by value, like the complex math type.

user3603401
  • 69
  • 1
  • 1
  • 6
    Just to be clear, I think this only applies to people using GCC on Windows. On Linux there is no compatibility breakage other than for C++11 users due to a bug in 4.7.0 and 4.7.1. Even that is fixed in 4.7.2, so just avoid the two bad point releases and you're fine. – John Zwinck Oct 08 '14 at 07:05