Static initialization and destruction of a static library's globals not happening with g++

前端 未结 1 1308
灰色年华
灰色年华 2020-12-09 03:13

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

相关标签:
1条回答
  • 2020-12-09 04:05

    .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.

    0 讨论(0)
提交回复
热议问题