Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking object files built using different versions of GCC

I have some compatibility concerns around the building of a C++ library with a modern version of GCC 4.4.x/4.5.x whereby clients on an older version, say 3.4.x/4.1.x. One solution which has been suggested is to compile the object files and distribute these. Clients can then link using any version of GCC and the relevant ABI. Some questions:

  1. Is this correct?
  2. Should I statically link to avoid libstdc++ compatibility issues?
  3. Is this unneccessary (I heard gcc 3.4 onwards is forwardly compatible)?

Cheers, Graeme

like image 668
Graeme Avatar asked Jan 17 '11 10:01

Graeme


1 Answers

The safest would be to give them a .so and its corresponding header with the stable binary API. To be binary stable that API should not accept or return any std:: types like std::string or std::vector<> because the binary layout of std:: types may change from version to version.

And it should be linked statically with libstdc++ and libgcc_s, so that your clients don't have to link against a particular version of libstdc++.

You can also pack all your .o files into one .a for convenience, so that when you add a new .o file your clients don't have to update their makefiles to link against the new .o.

like image 65
Maxim Egorushkin Avatar answered Oct 16 '22 13:10

Maxim Egorushkin