title: Global variables and scope - C++
body: <p>I am having small problem in making a global variable works. I am using Visual Studio 2008 and standard C++. </p>
  
  <p>I have two projects, one is a static library and second one is a test program which uses this library. I have a global variable in global.h like </p>
  
  <pre><code>#ifndef GLOBAL_H
  #define GLOBAL_H
  
  #include &lt;string&gt;
  
  extern std::string globalWord;
  
  #endif // GLOBAL_H!
  </code></pre>
  
  <p>I have a global.cpp where I am initializing this variable. This variable is used inside my library project. I am setting a value to this variable from the test project, but that value is not getting reflected in the library project. </p>
  
  <p>I have debugged and it shows the new value in test project, but when the control reaches the library project, this variable value shows empty. So is this global variable's scope only limited to the project where it belongs to?</p>
  
  <p>Or is there a better way to do this? I don't want to modify my function or constructor parameters in my library to pass this value.</p>
  
  <p>Any help would be great.</p>
  
  <p>Edit:</p>
  
  <p>Here is how this variable is declared in global.cpp</p>
  
  <pre><code>#include &lt;string&gt;
  #include "../global.h"
  
  std::string globalWord = "";
  </code></pre>
  
  <p>This is how I used it in my library</p>
  
  <pre><code>#include "../global.h"
  string text = globalWord;
  </code></pre>
  
  <p>Thanks</p>