title: c++ extern variable not visible
body: <p>I use extern variable for my application class so i can forward class function to glutDisplayFunction(funcPtr).</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "main.hpp"
  
  int main(int argc, char** argv)
  {
    gApp = new GameApp();
    return 0;
  }
  </code></pre>
  
  <p>main.hpp:</p>
  
  <pre><code>#ifndef MAIN_HPP
  #define MAIN_HPP
    #include "GameApp.hpp"
  #endif
  </code></pre>
  
  <p>GameApp.hpp:</p>
  
  <pre><code>#include &lt;GL/gl.h&gt;
  #include &lt;GL/freeglut.h&gt;
  
  class GameApp
  {
    public:
    int running;
  
    GameApp();
    virtual ~GameApp();
    void resize(int width, int height);
    void init(int argc, char** argv, int width, int height);
    void draw();
    void update();
    void key_input(unsigned char key, int x, int y);
  };
  
  extern GameApp *gApp;
  
  void display_clb()
  {
    if (!gApp)
    {
      return;
    }
  
    gApp-&gt;draw();
  }
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code>g++     -o dist/Debug/GNU-Linux-x86/gravity build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/GBody.o build/Debug/GNU-Linux-x86/GameApp.o build/Debug/GNU-Linux-x86/GBodyList.o -lm -lGL -lglfw -lGLU -lglut 
  build/Debug/GNU-Linux-x86/main.o: In function `main':
  /home/viktor/Documents/cpp/Gravity/main.cpp:6: undefined reference to `gApp'
  /home/viktor/Documents/cpp/Gravity/main.cpp:7: undefined reference to `gApp'
  /home/viktor/Documents/cpp/Gravity/GameApp.cpp:13: undefined reference to `gApp'
  /home/viktor/Documents/cpp/Gravity/GameApp.cpp:18: undefined reference to `gApp'
  build/Debug/GNU-Linux-x86/GameApp.o: In function `display_clb()':
  /home/viktor/Documents/cpp/Gravity/GameApp.cpp:23: undefined reference to `gApp'
  build/Debug/GNU-Linux-x86/GameApp.o:/home/viktor/Documents/cpp/Gravity/GameApp.cpp:28: more undefined references to `gApp' follow
  collect2: ld returned 1 exit status
  make[2]: *** [dist/Debug/GNU-Linux-x86/gravity] Error 1
  make[2]: Leaving directory `/home/viktor/Documents/cpp/Gravity'
  make[1]: *** [.build-conf] Error 2
  make[1]: Leaving directory `/home/viktor/Documents/cpp/Gravity'
  make: *** [.build-impl] Error 2
  </code></pre>
  
  <p>I expected gApp to be visible in my main.cpp and in GameApp class.</p>