title: OpenGL - Undefined references to GLUT
body: <p>I'm having a problem getting openGL to work on Windows 7 using MinGW at the moment. I'm following the steps found here: <a href="https://www.opengl.org/wiki/MinGW" rel="nofollow">https://www.opengl.org/wiki/MinGW</a></p>
  
  <p>I have installed MinGW and all of it's basic installation files. I have added the elements required to my PATH variable. I have downloaded and placed the GLUT files in the correct directories as described in the link above. Even so, with the below code I get the subsequent errors.</p>
  
  <pre><code>#include &lt;GL/glut.h&gt;
  
  void display (void) 
  {
      glClear (GL_COLOR_BUFFER_BIT);
  
      glBegin (GL_POLYGON);
        glVertex2f (-0.5, -0.5);
        glVertex2f (-0.5, 0.5);
        glVertex2f (0.5, 0.5);
        glVertex2f (0.5, -0.5);
      glEnd ();
  
      glFlush ();
      return;
  }
  
  int main (int argc, char **argv) 
  {
      glutInit (&amp;argc, argv);
      glutCreateWindow ("simple");
      glutDisplayFunc (display);
      glutMainLoop ();
  }
  </code></pre>
  
  <p>The command used to compile this program is:
  gcc firstProg.c -o firstProg.exe glut32.lib -lopengl32 -lglu32</p>
  
  <p>The error is as follows (taken from the cmd):</p>
  
  <pre><code>C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x1c): undefined
   reference to `__glutInitWithExit'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x37): undefined
   reference to `__glutCreateWindowWithExit'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x52): undefined
   reference to `__glutCreateMenuWithExit'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x66): undefined
   reference to `_imp__glClear'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x74): undefined
   reference to `_imp__glBegin'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x8c): undefined
   reference to `_imp__glVertex2f'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xa4): undefined
   reference to `_imp__glVertex2f'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xbc): undefined
   reference to `_imp__glVertex2f'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xd4): undefined
   reference to `_imp__glVertex2f'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xdb): undefined
   reference to `_imp__glEnd'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xe2): undefined
   reference to `_imp__glFlush'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x11f): undefine
  d reference to `glutDisplayFunc'
  C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x124): undefine
  d reference to `glutMainLoop'
  c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\D
  ylan\AppData\Local\Temp\cciCuMP6.o: bad reloc address 0x20 in section `.eh_frame
  '
  c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
   failed: Invalid operation
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>Anyone here have any idea how to solve these errors? I've tried uninstalling and reinstalling MinGW as well as placing the GLUT files within the required directories again but to no avail.</p>