Until some time ago, I thought a .a static library was just a collection of .o object files, just archiving them and not making them handled differently. But linking
.a
static libraries contain several .o
but they are not linked in unless you reference them from the main app.
.o
files standalone link always.
So .o
files in the linker always go inside, referenced or not, but from .a
files only referenced .o
object files are linked.
As a note, static global objects are not required to be initialized till you actually reference anything in the compilation unit, most compilers will initialize all of them before main, but the only requirement is that they get initialized before any function of the compilation unit gets executed.