title: Undefined references using GLUT with MinGW
body: <p>The initial command shown below yields the following errors while compiling an OpenGL program written in C.</p>
  
  <pre><code>C:\Users\razz\Desktop&gt;gcc -Wall -ofoo mycube.c -lglut32cu -lglu32 -lopengl32
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x1c): undefined reference to `__glutInitWithExit'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x37): undefined reference to `__glutCreateWindowWithExit'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x52): undefined reference to `__glutCreateMenuWithExit'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x66): undefined reference to `_imp__glClear'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x6d): undefined reference to `_imp__glLoadIdentity'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x9e): undefined reference to `_imp__glRotatef'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0xcf): undefined reference to `_imp__glRotatef'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0xdd): undefined reference to `_imp__glBegin'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0xfe): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x11f): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x140): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x161): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x182): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x1a3): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x1c4): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x1e5): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x1ec): undefined reference to `_imp__glEnd'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x1fa): undefined reference to `_imp__glBegin'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x21b): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x23c): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x25d): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x27e): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x29f): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x2a6): undefined reference to `_imp__glEnd'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x2b4): undefined reference to `_imp__glBegin'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x2d5): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x2f6): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x317): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x338): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x359): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x360): undefined reference to `_imp__glEnd'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x36e): undefined reference to `_imp__glBegin'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x38f): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x3b0): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x3d1): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x3f2): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x413): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x41a): undefined reference to `_imp__glEnd'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x428): undefined reference to `_imp__glBegin'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x449): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x46a): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x48b): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x4ac): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x4cd): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x4d4): undefined reference to `_imp__glEnd'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x4e2): undefined reference to `_imp__glBegin'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x503): undefined reference to `_imp__glColor3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x524): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x545): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x566): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x587): undefined reference to `_imp__glVertex3f'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x58e): undefined reference to `_imp__glEnd'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x595): undefined reference to `_imp__glFlush'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x59c): undefined reference to `glutSwapBuffers'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x617): undefined reference to `glutPostRedisplay'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x645): undefined reference to `glutInitDisplayMode'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x65d): undefined reference to `_imp__glEnable'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x66c): undefined reference to `glutDisplayFunc'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x678): undefined reference to `glutSpecialFunc'
  C:\Users\razz\AppData\Local\Temp\ccs833b1.o:mycube.c:(.text+0x67d): undefined reference to `glutMainLoop'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I am aware that this question has been asked before in threads titled "Undefined references using GLUT" and "GLUT program link error".</p>
  
  <p>Unfortunately, much of their jargon is above me so I am not quite sure how to apply their solutions. Second, given the dozens of possible configurations depending on the OS, the compiler, the version of GLUT, etc, I am not even certain if their scenario relates to mine. Here's my scenario:</p>
  
  <p><li>Using Windows 7 x64</p>
  
  <p><li>Using GLUT as provided here: <a href="http://www.prinmath.com/csci5229/misc/install.html" rel="noreferrer">http://www.prinmath.com/csci5229/misc/install.html</a> (download link is "my version of GLUT")</p>
  
  <p><li>The C program, should you care, is the one given at <a href="http://www.wikihow.com/Make-a-Cube-in-OpenGL" rel="noreferrer">http://www.wikihow.com/Make-a-Cube-in-OpenGL</a></p>
  
  <p><li>I have MinGW installed,  and the "gcc" command works; I have already successfully compiled a simple 'Hello World' C program</p>
  
  <p><li>The header file is located in C:\MinGW\include\GL\glut.h</p>
  
  <p><li>I placed glut32.dll in C:\Windows\system32 and C:\Windows\SysWOW64</p>
  
  <p><li>libglut32cu.a is in C:\MinGW\lib, C:\MinGW\usr\lib, C:\MinGW\usr\lib64. I know it only needs to be one, technically, but I tried all three hoping one of them would work. The instructions at the aforementioned PrinMath site suggest trying the latter two folders, it appears, when my error occurs. He also suggests using the "-L flag to tell the linker where it is". So I have tried entering this in the command prompt:</p>
  
  <pre><code>gcc -Wall -ofoo mycube.c -L"C:\MinGW\lib" -lglut32cu -lglu32 -lopengl32
  </code></pre>
  
  <p>Unfortunately, the result is the same.</p>