https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118811
--- Comment #20 from Jonathan Wakely <redi at gcc dot gnu.org> --- Because the constructors for globals in the libstdc++.so shared library are run before the ones in your program. This happens when the shared library is loaded into the process. When you link to libstdc++.a all the globals are in the same executable and the order of global constructors is unspecified (I think it depends on the order that the linker processes the various .o objects in the link, but formally the C++ standard says it's unspecified).