Note that there are some explanatory texts on larger screens.

plurals
  1. POGlobal variable has multiple copies on Windows and a single on Linux when compiled in both exec and shared libaray
    primarykey
    data
    text
    <p><strong>* Question revised (see below) *</strong></p> <p>I have a cpp file that defines a static global variable e.g.</p> <pre><code>static Foo bar; </code></pre> <p>This cpp file is compiled into an executable and a shared library. The executable may load the shared library at run time.</p> <p>If I am on Linux there seem to be two copies of this variable. I assume one comes from the executable and one from the shared library. Other platforms (HP, Windows) there seems to be only one copy.</p> <p>What controls this behavior on Linux and can I change it? For example is there a compiler or linker flag that will force the version of this variable from the shared library to be the same as the one from the executable?</p> <p><strong>* Revision of question *</strong></p> <p>Thanks for the answers so far. On re-examining the issue it is not actually the problem stated above. The static global variable above does indeed have multiple copies on Windows, so no difference to what I see on Linux.</p> <p><strong>However</strong>, I have another global variable (not static this time) which is declared in a cpp file and as extern in a header file.</p> <p>On Windows this variable has multiple copies, one in the executable and one in each dll loaded up, and on Linux it only has one. So the question is now about this difference. How can I make Linux have multiple copies?</p> <p>(The logic of my program meant the value of the static global variable was dependent of the value of the non-static global variable and I started accusing the wrong variable as being the problem)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload