Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using shared libraries and mismatched compilers

What are the chances using shared libraries that are compiled using different compiler versions than your program would introduce problems?

What if the language standard your programs use is different from their?

i.e Could it be a problem if I link boost libraries compiled with gcc-4.8,c++11 while compiling my code with gcc-6,c++14, for instance?

like image 836
xcorat Avatar asked Feb 05 '23 08:02

xcorat


1 Answers

If the ABI (and API) is the same, it will work fine, according to gcc.gnu.org's ABI Policy and Guidelines, "given an application compiled with a given compiler ABI and library API, it will work correctly with a Standard C++ Library created with the same constraints."

A shared library compiled with a different ABI could work, but there are some cases of which to be aware because they could cause major bugs which would be incredibly difficult to detect.

gcc-4.8 and gcc-6 have different ABIs (Application Binary Interfaces), and so could output different compiled code in very specific cases, and cause an application to break.

However, "the GNU C++ compiler, g++, has a compiler command-line option to switch between various different C++ ABIs." (According to ABI Policy and Guidelines.)

You can read more details about specific ABI issues from gcc.gnu.org:

like image 82
NonCreature0714 Avatar answered Feb 08 '23 17:02

NonCreature0714