glut.h not found after installing glut


I had face a problem that the glut.h still not found even I had already installed the glut.

main.c:20:21: error: GL\glut.h: No such file or directory
main.c: In function ‘Display’:
main.c:25: error: ‘GL_COLOR_BUFFER_BIT’ undeclared (first use in this function)
main.c:25: error: (Each undeclared identifier is reported only once
main.c:25: error: for each function it appears in.)
main.c:27: error: ‘GL_POLYGON’ undeclared (first use in this function)
main.c: In function ‘Reshape’:
main.c:42: error: ‘GL_PROJECTION’ undeclared (first use in this function)
main.c:47: error: ‘GLdouble’ undeclared (first use in this function)
main.c:47: error: expected ‘)’ before ‘x’
main.c:48: error: ‘GL_MODELVIEW’ undeclared (first use in this function)
main.c: In function ‘main’:
main.c:56: error: ‘GLUT_SINGLE’ undeclared (first use in this function)
main.c:56: error: ‘GLUT_RGB’ undeclared (first use in this function)

I install glut using synaptic manager. I had installed glutg-3, glutg3-dev, glut-doc, libglut3-dev, libglut3, freeglut3-dev, freeglut3, libgl1-mesa-dev, libgl1-mesa-glx and mesa-common-dev.

I had tried everything what I can. But still got this problem…Besides that, I go to /usr/include/GL to search for the glut.h. It is already there.

Anyone can tell me what happens?
Is it the library not yet linked? But I install everything using synaptic manager. Suppose it will link the library right? Please advise… I am using ubuntu 10.04

same ubuntu version, I only installed freeglut3-dev, and correctly got :

Now try doing :
#include <GL/glut.h>

(forward slash instead of backslash on unix systems)

Hem…dint notice that…
I download the example code from web. I change ade but now other problems come:

/tmp/ccObaJaj.o: In function `Display':
main.c:(.text+0xe): undefined reference to `glClear'
main.c:(.text+0x13): undefined reference to `glLoadIdentity'
main.c:(.text+0x1f): undefined reference to `glBegin'
main.c:(.text+0x3e): undefined reference to `glColor3f'
main.c:(.text+0x5d): undefined reference to `glVertex3f'
main.c:(.text+0x7c): undefined reference to `glColor3f'
main.c:(.text+0x9b): undefined reference to `glVertex3f'
main.c:(.text+0xba): undefined reference to `glColor3f'
main.c:(.text+0xd9): undefined reference to `glVertex3f'
main.c:(.text+0xde): undefined reference to `glEnd'
main.c:(.text+0xe3): undefined reference to `glFlush'
/tmp/ccObaJaj.o: In function `Reshape':
main.c:(.text+0x103): undefined reference to `glMatrixMode'
main.c:(.text+0x108): undefined reference to `glLoadIdentity'
main.c:(.text+0x136): undefined reference to `gluPerspective'
main.c:(.text+0x142): undefined reference to `glMatrixMode'
main.c:(.text+0x164): undefined reference to `glViewport'
/tmp/ccObaJaj.o: In function `main':
main.c:(.text+0x187): undefined reference to `glutInit'
main.c:(.text+0x193): undefined reference to `glutInitDisplayMode'
main.c:(.text+0x1a7): undefined reference to `glutInitWindowSize'
main.c:(.text+0x1b3): undefined reference to `glutCreateWindow'
main.c:(.text+0x1db): undefined reference to `glClearColor'
main.c:(.text+0x1e7): undefined reference to `glutDisplayFunc'
main.c:(.text+0x1f3): undefined reference to `glutReshapeFunc'
main.c:(.text+0x1f8): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status

What is the problem?Sorry about that I just starting to learn openGL.

Here is the source code:



  June, 7th, 2000

  This tutorial was written by Philipp Crocoll



  Every comment would be appreciated.

  If you want to use parts of any code of mine:

	let me know and

	use it!


#include <GL/glut.h>

void Display(void)












	glFlush();			//Finish rendering


void Reshape(int x, int y)


	if (y == 0 || x == 0) return;  //Nothing is visible then, so return

	//Set a new projection matrix



	//Angle of view:40 degrees

	//Near clipping plane distance: 0.5

	//Far clipping plane distance: 20.0



	glViewport(0,0,x,y);  //Use the whole window for rendering


int main (int argc, char **argv)


	//Initialize GLUT

	glutInit(&argc, argv);

	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


	//Create a window with rendering context and everything else we need



	//Assign the two used Msg-routines



	//Let GLUT get the msgs


	return 0;


Undefined reference means although declaration was found in some .h, the linker did not find a library to link with.
Ie. pass -lGL to your gcc compile line, to link with

Can show some example of code?

I had another question. Now the why i cannot locate the glut.h? But gl.h can be located?

What is your current compile line ?
It should look like this :
gcc collect2.c -lglut -lGLU -lGL

Because the ‘locate’ command is not realtime, but searches an index which is typically build once a day.
Do this to be certain to search uptodate info :
sudo updatedb

Yeah…You solve my problem…Thank you… :smiley:

How do you know which should library be linked? IT means that I always need to link the library for every compilation of code?

How to make it permanently link automatically like other library?

The idea is whenever you #include something else than stdio.h/stdlib.h you probably have to add a -lsomelib argument to the linker. Take C course if you need details, this is not specific to OpenGL.

Ok…Thanks a lot…