PDA

View Full Version : glut.h not found after installing glut



SagoO
11-13-2010, 03:00 AM
Hi,

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

ZbuffeR
11-13-2010, 03:28 AM
same ubuntu version, I only installed freeglut3-dev, and correctly got :
/usr/include/GL/freeglut.h
/usr/include/GL/glut.h

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

(forward slash instead of backslash on unix systems)

SagoO
11-13-2010, 03:57 AM
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:

/************************************************** ********************



OpenGL-Introduction



June, 7th, 2000



This tutorial was written by Philipp Crocoll

Contact:

philipp.crocoll@web.de

www.codecolony.de



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)

{

glClear(GL_COLOR_BUFFER_BIT);

glLoadIdentity();

glBegin(GL_POLYGON);

glColor3f(0.0,0.0,0.0);

glVertex3f(-0.5,-0.5,-3.0);

glColor3f(1.0,0.0,0.0);

glVertex3f(0.5,-0.5,-3.0);

glColor3f(0.0,0.0,1.0);

glVertex3f(0.5,0.5,-3.0);

glEnd();

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

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

//Angle of view:40 degrees

//Near clipping plane distance: 0.5

//Far clipping plane distance: 20.0

gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);

glMatrixMode(GL_MODELVIEW);

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

}



int main (int argc, char **argv)

{

//Initialize GLUT

glutInit(&amp;argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(300,300);

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

glutCreateWindow("Intro");

glClearColor(0.0,0.0,0.0,0.0);

//Assign the two used Msg-routines

glutDisplayFunc(Display);

glutReshapeFunc(Reshape);

//Let GLUT get the msgs

glutMainLoop();

return 0;

}

ZbuffeR
11-13-2010, 04:24 AM
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 libGL.so

SagoO
11-13-2010, 04:35 AM
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?

ZbuffeR
11-13-2010, 12:14 PM
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

SagoO
11-13-2010, 12:42 PM
Yeah...You solve my problem...Thank you... :D

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?

ZbuffeR
11-13-2010, 01:35 PM
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.

SagoO
11-13-2010, 08:04 PM
Ok...Thanks a lot...