Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do static libraries behave like dynamic libraries in terms of ABI compatibility?

I have learned that you cannot use shared libraries compiled with different compilers together because their ABIs are usually incompatible. The exception is of course if you have a pure C interface, then it is possible. However, I did not find a clear statement about static libraries in this regard, hence this question.

My question is if static libraries have the same issue. If my shared library links against a static library from a different compiler, will it compile and work as expected at runtime? Or will it compile and behave badly? Or will it never compile?

like image 562
Fabian Avatar asked Oct 22 '25 04:10

Fabian


1 Answers

There are several kinds of mismatches which could occur, including:

  1. Name mangling. This is a major reason why different compilers may be incompatible. However, many compilers are cross-compatible.
  2. Calling conventions. How to pass function arguments, return values, etc. Tends to be tied to the CPU architecture and operating system.
  3. Language types. For example int can have different widths on different operating systems.
  4. Library types. Commonly std::string, std::map and other classes can be implemented differently by each library vendor, and since many people use the standard library provided by their compiler vendor, this issue may arise.

Some of these, like name mangling, are likely to result in build failures. Others may seem to build OK but behave unexpectedly at runtime. Whether you're using static or dynamic linking, the overall situation is the same.

like image 131
John Zwinck Avatar answered Oct 23 '25 18:10

John Zwinck