title: LNK2005 (already defined) can't find error
body: <p>I have what seems to be a common question but I can't seem to solve it in the context of my code. I've recently started a class where I've been thrown into C++ and OpenGL with no prior knowledge of C++ so please be easy on me. Here's my 3 files, meant to open an OpenGL window; however I'm greeted with a nice LNK2005 error:</p>
  
  <blockquote>
    <p>error LNK2005: "public: static unsigned int JWindow::id" (?id@JWindow@@2IA) already defined in Application.obj    X:\School\comp2501\COMP2501Tutorial1\COMP2501Tutorial1\Main.obj ‌​COMP2501Tutorial1</p>
  </blockquote>
  
  <p>I can't seem to find where I've redefined things to give me this error.</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;windows.h&gt;       // Standard header for MS JWindows applications
  #include &lt;freeglut.h&gt;
  #include "Application.h"
  
  #define KEY_ESCAPE 27
  
  static GLfloat lightPos[] = { 1.0, 1.0, 1.0, 0.0 };
  
  void drawCube(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1, GLdouble z0, GLdouble z1) {/**/}
  
  int main(int argc, char **argv) {
  
      JWindow::create(640, 480, "Tutorial 1", 45.0f, 0.1f, 500.0f);
  
      // initialize and run program
      glutInit(&amp;argc, argv);                                      // GLUT initialization
      glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);  // Display Mode (RGBA color|two screen buffers| use depth buffer)
  
      glutInitWindowSize(JWindow::width, JWindow::height);                // set JWindow size
  
      glutDisplayFunc(JWindow::display);                                  // register display function
      glutIdleFunc(JWindow::display);                                     // register idle function
      glutKeyboardFunc(JWindow::keyboard);                                    // register keyboard function
      glutCloseFunc(JWindow::close);                                       // register close function
  
  
      JWindow::initialize();                                              // intialization
       glutMainLoop();                                                // run GLUT mainloop
  }
  </code></pre>
  
  <p>Application.h</p>
  
  <pre><code>class JWindow{
  public:
      static void updateProjection();
      static void render();
      static void initialize();
      static void timer(int);
      static void display();
      static void close();
      static void create(int, int, char*, float, float, float);
      static void keyboard(unsigned char, int, int);
  
      static GLuint id;
      static char* title;
  
      static int width;
      static int height;
  
      static float fovAngle;
  
      static float zNear;
      static float zFar;
  
  };
  
  
  GLuint JWindow::id = 0;
  char* JWindow::title = "JWindow";
  int JWindow::width = 0;
  int JWindow::height = 0;
  float JWindow::fovAngle = 0.0f;
  float JWindow::zNear = 0.0f;
  float JWindow::zFar = 0.0f;
  </code></pre>
  
  <p>Application.cpp</p>
  
  <pre><code>#include &lt;freeglut.h&gt;
  #include "Application.h"
  
  #define KEY_ESCAPE 27
  
  void JWindow::updateProjection()
  {
      glutSetWindow(JWindow::id);                                                      // tell opengl which JWindow you want to change
      JWindow::height = (JWindow::height &lt; 1) ? 1 : JWindow::height;                            // make sure we are not dividing by zero for the aspect
      glViewport(0, 0, JWindow::width, JWindow::height);                                  // set the viewport
  
      glMatrixMode(GL_PROJECTION);                                                // select projection matrix
      glLoadIdentity();                                                           // reset projection matrix
  
      GLfloat aspect = (GLfloat)JWindow::width / JWindow::height;                           // calculate aspect ratio
      gluPerspective(JWindow::fovAngle, aspect, JWindow::zNear, JWindow::zFar);       // set up a perspective projection matrix
   }
  
  
  // Render data to the screen
  void JWindow::render()
  {
  glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);          // Clear Screen and Depth Buffer
  glMatrixMode(GL_MODELVIEW);                                  // Tell opengl we are working with the modelview matrix
  glLoadIdentity();                                            // Set the modelview matrix to the identity matrix
  
  gluLookAt(0.0f, 0.0f, 10.0f,    //position
      0.0f, 0.0f, 0.0f,     //look at position
      0.0f, 1.0f, 0.0f);    //up vector
  /*
  glBegin(GL_TRIANGLES);              // Send the following information as triangles
  glColor4f(1.0f, 0.0f, 0.0f, 1.0f);  // glColor4f(red,green,blue,alpha)
  glVertex3f(-1.0f, -1.0f, 0.0f);     // glVertex3f(x,y,z)
  
  glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
  glVertex3f(1.0f, -1.0f, 0.0f);
  
  glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
  glVertex3f(-1.0f, 1.0f, 0.0f);
  
  glEnd();                            // tell opengl we are done sending data
  */
      //drawCube(-1, 1, -1, 1, -1, 1);
      glutSolidTorus(1, 2, 10, 10);
      glutSwapBuffers(); //works with GL_DOUBLE. use glFlush(); instead, if using GL_SINGLE
  }
  
  // Function called when timer ends
  void JWindow::timer(int id) {
      glutPostRedisplay();         // Tell GLUT to call it's glutDisplayFunc
  }
  
  // Set new timer and render
  void JWindow::display(void)
  {
      glutTimerFunc(17, timer, 1); //Call timer function in at least 17 milliseconds
      glutSetWindow(JWindow::id);      //Tell glut which JWindow we are working on (only needed for multiple JWindows)
  JWindow::render();           //Call our render function
  }
  
  //get keyboard input
  void JWindow::keyboard(unsigned char key, int mousePositionX, int mousePositionY)
  {
      switch (key)
      {
      case KEY_ESCAPE:
          glutExit();    //if ESC key is pressed, quit
          break;
  
      default:
          break;
      }
  }
  
  // callback function when glut ends
  void JWindow::close()
  {
      //memory cleanup when program quits
  }
  
  void JWindow::initialize()
  {
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
      glCullFace(GL_BACK);
      glClearColor(0.0, 0.0, 0.0, 1.0);
  
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
  
      glViewport(0, 0, JWindow::width, JWindow::height);                      // set the viewport
  
      glMatrixMode(GL_PROJECTION);                                    // select projection matrix
      glLoadIdentity();                                               // reset projection matrix
      GLfloat aspect = (GLfloat)JWindow::width / JWindow::height;             // calculate aspect ratio
      gluPerspective(JWindow::fovAngle, aspect, JWindow::zNear, JWindow::zFar);   // set up a perspective projection matrix
  
  }
  
  void reshape(GLint newWidth, GLint newHeight) {
  
  }
  
  void JWindow::create(int w, int h, char* t, float fov, float n, float f){
      JWindow::width = w;
      JWindow::height = h;
      JWindow::title = t;
      JWindow::fovAngle = fov;
      JWindow::zNear = n;
      JWindow::zFar = f;
      JWindow::id = glutCreateWindow(JWindow::title);
  }
  </code></pre>