5

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

Frumples
  • 425
  • 1
  • 4
  • 18
  • 1
    dll file is a dynamicly loaded library (it's needed during runtime). When you are linking your app, you need to link against static library (a file with extension .a or .lib). You can tell the compiler where to look for static libraries with -L switch (similar to -I for headers). – tumdum Jan 19 '14 at 09:30

2 Answers2

0

You need to link to glut binary:

g++ GLtest1.cpp -lglut32
tumdum
  • 1,981
  • 14
  • 19
  • 1. I have to link every time I compile code? 2. Would you recommend doing "-lglut64" for a Windows 64 bit OS? – Frumples Jan 18 '14 at 22:59
  • Yes, to have working binary, you need to perform linking every time. Yes, I would expect that for win64, the name will change to glut64. – tumdum Jan 18 '14 at 23:01
  • C:\code\cpp>g++ GLtest1.cpp -lglut32 c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lglut32 collect2.exe: error: ld returned 1 exit status – Frumples Jan 18 '14 at 23:05
  • try something from http://stackoverflow.com/questions/12919277/glut-program-link-error – tumdum Jan 18 '14 at 23:06
  • I edited my question after having tried a few of the things from the link you provided. – Frumples Jan 19 '14 at 00:48
0

My case : I switched the lib files and bin file from 64bit to 32bit. And it worked.

lsc4719
  • 17
  • 1
  • 1
  • 4