code does not compile!!!!!!

i am using c++ as
the programming language. i am a new user in open gl
and glut. wrote the following code and tried to
compile it with the following command:
g++ -o hi hi.cpp -L/usr/X11R6/lib -lGLU -lGL -ldl -lSM -lICE -lXi -lXmu -lXext -lX11 -lm
my code is as follows:
#include<GL/gl.h>
#include<GL/glut.h> void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glBegin (GL_POLYGON);
glVertex3f (0.25,0.25,0.0);
glVertex3f (0.75,0.25,0.0);
glVertex3f(0.75,0.75,0.0);
glVertex3f(0.25,0.75,0.0);
glEnd();
glFlush ();
}
void init(void)
{
glClearColor (0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
}
int main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplaymode (GLUT_SINGLE | GLUT_RGB );
glutInitWindosize (250,250);
glutInitWindowPosition (100,100);
glutCreateWindow (“hello”);
init();
glutDisplayFunc(display);
void glutmainLoop(void);
return 0;
}

i got the following errors:
tmp/cc7rePCk.o(.text+0x169): In function main': : undefined reference toglutInit’
/tmp/cc7rePCk.o(.text+0x176): In function main': : undefined reference toglutInitDisplayMode’
/tmp/cc7rePCk.o(.text+0x18b): In function main': : undefined reference toglutInitWindowSize’
/tmp/cc7rePCk.o(.text+0x19a): In function main': : undefined reference toglutInitWindowPosition’
/tmp/cc7rePCk.o(.text+0x1aa): In function main': : undefined reference toglutCreateWindow’
/tmp/cc7rePCk.o(.text+0x1bf): In function main': : undefined reference toglutDisplayFunc’

i had got a similar problem when i had started working
with c++ on suse 9.1.
then i was getting error as
cout undefined. definre it first.
i addded the folowing line to my code
#using namespace std;
//std::cout

please help me solve my problem.
waiting for you reply
vijay rana

You have forgotten to include the glut library in your compile command:

g++ -o hi hi.cpp -L/usr/X11R6/lib -lGLU -lGL -ldl -lSM -lICE -lXi -lXmu -lXext -lX11 -lm

should be like this:

g++ -o hi hi.cpp -L/usr/X11R6/lib -lglut -lGLU -lGL -ldl -lSM -lICE -lXi -lXmu -lXext -lX11 -lm

By the way you actually only need to #include <GL/glut.h>
it already includes all the other gl headers.
-but that won’t give you an error.

Hi,

First learn how to compile. As pointed out you have not included glut, so such an error will be common irrespective of library used.

Try simple cmd line: g++ -o hi hi.cpp -lglut -lGL -lGLU

I tried and it works. U have not used any Motif calls… so why bother ur Xt libs!

Second try to copy the code properly.
You will get 3 errors - check comments inline

  
glutInit (&argc, argv);
glutInitDisplaymode (GLUT_SINGLE | GLUT_RGB );
- Wrong func name is glutInitDisplayMode ..
glutInitWindosize (250,250);
- typo mistake.. did u see ur code properly?
it should be glutInitWindowSize
glutInitWindowPosition (100,100);
glutCreateWindow ("hello");
init();
glutDisplayFunc(display);
void glutmainLoop(void);
-- is this definition or declaration?
 

bye
ketan

Note: Use Red book to learn things properly. Will help in long run.