What happens to static variables when libraries are statically linked
<p>Let's say I have library <code>(A)</code> implementing the singleton pattern (it has a static variable in its implementation).</p>

<p><code>(A)</code> library is compiled as a static library.</p>

<p>Now, let's say I have in my probject:</p>

<ul>
<li><code>(B)</code>, another static library linking statically with <code>(A)</code>. </li>
<li><code>(C)</code>, another static library linking statically with <code>(A)</code>. </li>
<li><code>(D)</code>, a top level program linking with <code>(B)</code> and <code>(C)</code>.</li>
</ul>

<p>In the end, is my singleton really a singleton (and my variable really static)? Are <code>(B)</code> and <code>(C)</code> seing the same static variable from <code>(A)</code> (is it unic)? Or does the fact that <code>(A)</code> was statically linked twice embedded <code>(A)</code>'s code twice ending up with my static variable from <code>(A)</code> appearing twice in the final binary code? Then if <code>(B)</code> modifies the static variable value, <code>(C)</code> would not see the change?</p>

<p>Note: I experienced that when changing the libraries of project to be linked statically instead of dynamically. I'm just wondering if I did something wrong, or if that's a normal known behaviour.</p>