title: Undefined reference to glut functions
body: <p>This is my first time coding regarding openGL and I've been having a lot of trouble with getting all of the functions to work for it. This is a program given to us by our teacher that should have no error or problems in it. I am using MinGW and the latest version of freeglut. I have created the paths in environment variables and I have added all the libraries and their paths as well. </p>
  
  <pre><code>#define GLUT_DISABLE_ATEXIT_HACK
  
  # include &lt;windows.h&gt;
  # include &lt;stdlib.h&gt;
  # include &lt;GL/freeglut.h&gt;
  
  GLfloat vertices[][3] = {{-1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}};
  
  GLfloat colors[][3]= { {0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {0.0, 1.0, 1.0} };
  
  bool stop = false;
  
  void face(int a, int b, int c, int d)
  {
  
      glBegin(GL_POLYGON);
      glColor3fv(colors[a]);
      glVertex3fv(vertices[a]);
      glColor3fv(colors[b]);
      glVertex3fv(vertices[b]);
      glColor3fv(colors[c]);
      glVertex3fv(vertices[c]);
      glColor3fv(colors[d]);
      glVertex3fv(vertices[d]);
      glEnd();
  }
  
  void colorcube()
  {
      face(0, 3, 2, 1);
      face(2, 3, 7, 6);
      face(0, 4, 7, 3);
      face(1, 2, 6, 5);
      face(4, 5, 6, 7);
      face(0, 1, 5, 4);
  }
  
  static GLfloat theta[] = {0.0, 0.0, 0.0};
  static GLint axis = 2;
  
  void display()
  {
  
  
      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
      glShadeModel(GL_SMOOTH);
      glLoadIdentity();
      glRotatef(theta[0], 1.0, 0.0, 0.0);
      glRotatef(theta[1], 0.0, 1.0, 0.0);
      glRotatef(theta[2], 1.0, 0.0, 1.0);
  
      colorcube();
  
      glFlush();
      glutSwapBuffers();
  }
  
  
  
  void spinCube()
  {
      theta[axis] += 2.0;
      if (theta[axis] &gt; 360,0) theta[axis] -= 360;
      glutPostRedisplay();
  }
  
  void mouse(int btn, int state, int x, int y)
  {
      if (btn == GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_DOWN) axis = 0;
      if (btn == GLUT_MIDDLE_BUTTON &amp;&amp; state == GLUT_DOWN) axis = 1;
      if (btn == GLUT_RIGHT_BUTTON &amp;&amp; state == GLUT_DOWN) axis = 2;
  }
  
  void keyboard(unsigned char key, int x, int y)
  {
      if (key == 'q' || key == 'Q') exit(0);
      if (key == ' ') stop = !stop;
      if (stop)
          glutIdleFunc(NULL);
      else
          glutIdleFunc(spinCube);
  }
  
  void myReshape(int w, int h)
  {
      glViewport(0, 0, w, h);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(-2.0, 2.0, -2.0,
              2.0, -10.0, 10.0);
      //if (w &lt;= h)
      // glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
      // 2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
      // else
      // glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
      // 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
  
      glMatrixMode(GL_MODELVIEW);
  
  }
  
  int main(int argc, char **argv)
  {
      glutInit(&amp;argc, argv);
  
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
      glutInitWindowSize(500, 500);
      glutCreateWindow("colorcube");
      glutReshapeFunc(myReshape);
      glutDisplayFunc(display);
      glutIdleFunc(spinCube);
      glutMouseFunc(mouse);
      glutKeyboardFunc(keyboard);
      glEnable(GL_DEPTH_TEST);
      glutMainLoop();
  }
  </code></pre>
  
  <p>Next is the error in console that it is giving me, nothing about not being able to find the libraries just that the variables are undefined.</p>
  
  <pre><code>16:19:35 **** Incremental Build of configuration Debug for project spinningCube ****
  Info: Internal Builder is used for build
  g++ "-IC:\\MinGW\\freeglut\\include" "-IC:\\MinGW\\include" "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.8.1" "-IC:\\MinGW\\mingw32\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "..\\main.cpp" 
  ..\main.cpp: In function 'void spinCube()':
  ..\main.cpp:70:21: warning: left operand of comma operator has no effect [-Wunused-value]
       if (theta[axis] &gt; 360,0) theta[axis] -= 360;
                       ^
  g++ "-LC:\\MinGW\\freeglut\\lib\\x64\\Debug" -o spinningCube.exe main.o -lglu32 -lopengl32 -lfreeglut 
  main.o: In function `Z7displayv':
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:62: undefined reference to `_imp__glutSwapBuffers@0'
  main.o: In function `Z8spinCubev':
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:71: undefined reference to `_imp__glutPostRedisplay@0'
  main.o: In function `Z8keyboardhii':
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:86: undefined reference to `_imp__glutIdleFunc@4'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:88: undefined reference to `_imp__glutIdleFunc@4'
  main.o: In function `main':
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:111: undefined reference to `_imp__glutInit@8'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:113: undefined reference to `_imp__glutInitDisplayMode@4'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:114: undefined reference to `_imp__glutInitWindowSize@8'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:115: undefined reference to `_imp__glutCreateWindow@4'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:116: undefined reference to `_imp__glutReshapeFunc@4'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:117: undefined reference to `_imp__glutDisplayFunc@4'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:118: undefined reference to `_imp__glutIdleFunc@4'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:119: undefined reference to `_imp__glutMouseFunc@4'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:120: undefined reference to `_imp__glutKeyboardFunc@4'
  C:\Users\Josh Donckels\workspace\spinningCube\Debug/../main.cpp:122: undefined reference to `_imp__glutMainLoop@0'
  collect2.exe: error: ld returned 1 exit status
  
  16:19:36 Build Finished (took 1s.89ms)
  </code></pre>