且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

静态初始化和销毁​​静态库的全局变量不会发生在g ++

更新时间:2023-11-15 10:12:28

.a .o ,但它们不会链接,除非您从主应用程序中引用它们。

.o

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

因此,链接器中的 .o 文件总是进入,但是 .a 文件只引用 .o 对象文件。

So .o files in the linker always go inside, referenced or not, but from .a files only referenced .o object files are linked.

注意,静态全局对象不需要被初始化,直到你实际上引用编译单元中的任何东西,大多数编译器将在main之前初始化它们,但是唯一的要求是它们在任何函数之前被初始化的编译单元被执行。

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.