I want to ask you about object files (*.o, .obj) and static libraries (.a, *.lib). As far as I know, static libraries must match with compilers, so they are compiler-specific. Is it true? How does it look like if it comes to object files? Object files are consisted of binarny code, so it is tempting to assume that I can use them with all compillers. I am looking forward your answears.
-
2Object files and libraries are usually made for a specific *target*. It is usually possible to use object files made for a specific target by one compiler, together with a object files made for the same specific target by another compiler. The important thing is that both compilers use the same [*Application Binary Interface (ABI)*](https://en.wikipedia.org/wiki/Application_binary_interface). – Some programmer dude Sep 05 '18 at 17:23
-
1_"Object files are consisted of binarny code, so it is tempting to assume that I can use them with all compillers."_ Why's that? They don't exist in a vacuum! They almost always link with some runtime, at the very least. – Lightness Races in Orbit Sep 05 '18 at 17:27
2 Answers
As far as I know, static libraries must match with compilers, so they are compiler-specific. Is it true?
Yes, that's true.
Object files are consisted of binarny code, so it is tempting to assume that I can use them with all compillers.
Static libraries aren't anything else than accumulated .o
files, so no other rule applies for these.

- 1
- 13
- 116
- 190
-
Could you go into more detail why static libraries list match with compillers? I trying to understand it – Kasata Ata Sep 05 '18 at 17:40
-
@KasataAta It's just what [@someprogrammerdude commented](https://stackoverflow.com/questions/52190432/compilation-products-portability/52190479?noredirect=1#comment91330713_52190432) and that's already true for `.o` files. As mentioned a static library is just a collection of `.o` files. – πάντα ῥεῖ Sep 05 '18 at 17:44
VISUAL STUDIO ANSWER
For visual studio, a .lib
is just a container of .obj
and so which one doesn't change the answer.
Also whether a LIB must match a specific version of the compiler depends. With ltcg they must match. Without it ... it depends. A clean, c interface library probably is ok to use with different versions of a compiler. When C++/STL gets in the mix things can start to go wrong. So the best advice is just use the same version - don't risk it. You may get away with it for a while but unless you're very careful you'll eventually trip up.
And by the same version generally the same major version is suffice - VS team really try to not break binary compat in minor version updates
No idea about .o or .a

- 9,468
- 25
- 44