MinGW and GLUT undefined reference to '_imp____glutInitWithExit@12'

Frumples picture Frumples · Jan 18, 2014 · Viewed 9k times · Source

I dabbled in Python for a year, and am starting c++, so I am a noob. I installed MinGW and had everything working fine until I installed freeglut. When I run the following code:

#include <gl/glut.h>

int main()
{
    return 0;
}

using:

C:\code\cpp>g++ GLtest1.cpp

I get this:

C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x1c): undefined
reference to `_imp____glutInitWithExit@12'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x3e): undefined
reference to `_imp____glutCreateWindowWithExit@8'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x60): undefined
reference to `_imp____glutCreateMenuWithExit@8'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\U
ser\AppData\Local\Temp\ccABWOyv.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

I installed and re-installed MinGW several times in an attempt to remedy the problem, but to no avail. I tried using

#include <windows.h> 

as well. I tried installing the 64 bit .dll files--nothing. If anyone has experienced this before, or is familiar with my problem, some assistance would be welcome. Thank you. I'm guessing I need to do something with "linking", but I really don't see why "glut.h" should be any different than "gl.h", or "glu.h". SO FRUSTRATING!

Update:

I attempted to link a few things. First I did this:

C:\code\cpp>g++ -c -o GLtest1.exe GLtest1.cpp -I"C:\MinGW\include"

and it worked out all right. No errors. Then I tried to link things around and ended up with an error:

C:\code\cpp>g++ -o GLtest1.exe -L"C:\MinGW\lib" -lglut32 -opengl32
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot fin
d -lglut32
collect2.exe: error: ld returned 1 exit status

Any ideas here? glut32.dll exists in both System32 and SysWOW64

Answer

tumdum picture tumdum · Jan 18, 2014

You need to link to glut binary:

g++ GLtest1.cpp -lglut32