2
votes

A week ago, when I first tried to work with GLUT and followed this tutorial it worked without any errors. Now, a week later I installed the same software, same libraries, but every time I try to compile the project I get these errors (and it highlights a line in the glut.h file):

obj\Debug\main.o(.text+0x1c)||In function `glutInit_ATEXIT_HACK':|
C:\Program Files\CodeBlocks\MinGW\include\GL\glut.h|486|undefined reference to `__glutInitWithExit@12'|
obj\Debug\main.o(.text+0x3d)||In function `glutCreateWindow_ATEXIT_HACK':|
C:\Program Files\CodeBlocks\MinGW\include\GL\glut.h|503|undefined reference to `__glutCreateWindowWithExit@8'|
obj\Debug\main.o(.text+0x5d)||In function `glutCreateMenu_ATEXIT_HACK':|
C:\Program Files\CodeBlocks\MinGW\include\GL\glut.h|549|undefined reference to `__glutCreateMenuWithExit@8'|

I uninstalled Code:Blocks, deleted the GLUT files (glut.h, glut32.dll, glut.a) and reinstalled everything, but I still get the same errors. I'm completely sure my linker settings are OK since I've followed the tutorial. I also tried other tutorials, but get the same results, a bunch of errors.

What am I doing wrong, and how can I fix it?

Edit: Fixed! All that was needed was #include <GL/gl.h> before including GL/glut.h.

2
#pragma comment(lib, "glut32.lib") add it at the top of main.cpp - Blood
I'm using Code::Blocks, not Microsoft Visual C++ - Broxzier
So what? It's preprocessor definition, not IDE command. - Blood
I thought #pragma was VC++ only, when I added it I only get more errors. "warning: ignoring #pragma comment" - Broxzier
Okay, fixed it. I had to add #include <GL/gl.h> before #include <GL/glut.h>. I'm not sure why, but now all example codes I checked work if I do so. - Broxzier

2 Answers

4
votes

I had to add #include <GL/gl.h> before #include <GL/glut.h>. I'm not sure why, but now all examples seem to compile just fine.

0
votes

I don't know why my comment get deleted, but in the end it did work by adding windows.h library ...