Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined references using GLUT with MinGW

The initial command shown below yields the following errors while compiling an OpenGL program written in C.

C:\Users\razz\Desktop>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

I am aware that this question has been asked before in threads titled "Undefined references using GLUT" and "GLUT program link error".

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:

  • Using Windows 7 x64

  • Using GLUT as provided here: http://www.prinmath.com/csci5229/misc/install.html (download link is "my version of GLUT")

  • The C program, should you care, is the one given at http://www.wikihow.com/Make-a-Cube-in-OpenGL

  • I have MinGW installed, and the "gcc" command works; I have already successfully compiled a simple 'Hello World' C program

  • The header file is located in C:\MinGW\include\GL\glut.h

  • I placed glut32.dll in C:\Windows\system32 and C:\Windows\SysWOW64

  • 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:
    gcc -Wall -ofoo mycube.c -L"C:\MinGW\lib" -lglut32cu -lglu32 -lopengl32
    

    Unfortunately, the result is the same.

  • like image 894
    cadsharp Avatar asked Jan 19 '13 07:01

    cadsharp


    2 Answers

    At the top of the source file mycube.c you have to include

    #include<windows.h>
    

    or include

    #include<GL/gl.h> or #include<GL/glu.h>
    

    Then compile you code there will be no such type of error.

    like image 60
    Dinesh Subedi Avatar answered Oct 15 '22 18:10

    Dinesh Subedi


    The glut library you downloaded was built for 32-bit programs. It looks like your MinGW is building for a 64-bit target, which uses different names than the 32-bit (and is incompatible anyway).

    Try adding the -m32 option to get MinGW to builds a 32-bit program:

    gcc -m32 -Wall -ofoo mycube.c -L"C:\MinGW\lib" -lglut32cu -lglu32 -lopengl32
    

    Note that mt 64-bit MinGW compiler (gcc version 4.6.1 (tdm64-1) from http://tdm-gcc.tdragon.net/download) gives a small clue about this problem:

    ld.exe: skipping incompatible .\glut32\lib/libglut32cu.a when searching for -lglut32cu
    ld.exe: cannot find -lglut32cu
    
    like image 30
    Michael Burr Avatar answered Oct 15 '22 20:10

    Michael Burr