title: c++ Global Variables Across Multiple Files
body: <p>I have some code spread over three files and I would like to use a fourth "gloabls" file to store some physical constants such as the value of pi.  This would avoid repetitive definitions of <code>pi = 4*atan(1.0)</code>.  After poking around, what I've tried is creating a global header file:</p>
  
  <pre><code>/*globals.h*/
  extern double g_pi;
  </code></pre>
  
  <p>and a global cpp file:</p>
  
  <pre><code>/*globals.cpp*/
  #include "math.h"
  #include "globals.h"
  double g_pi = 4*atan(1.0);
  </code></pre>
  
  <p>Then I include these file in my main files:</p>
  
  <pre><code>/*mainFile.cpp*/
  //Include math and other libraries 
  #include globals.h"
  int main() {
  /*
  ....
  */
  double x = 2*g_pi
  /*
  ....
  */
  }
  </code></pre>
  
  <p>This gives me an undefined reference error to g_pi. I'm using a g++ compiler on Ubuntu.  Hopefully its a simple fix! Your suggestions are much appreciated.  If more details are necessary I'll be happy to supply them.</p>