On Linux, I have generated C ++ code from a static library that defines a global variable. One instance of this global variable is shared between two shared libraries that reference its symbol.
When the process terminates and the static completion phase starts, I see that the destructor on this shared instance starts twice! Presumably once per library at each load.
This question is closely related to another that I recently saw here: a related question . This is similar to the same behavior, but it is not discussed why this is happening.
Does anyone know a theoretical explanation for this behavior?
c ++ linux global-variables destructor shared-libraries
Scott Cameron
source share