Compiling Errors, why?

I get these errors compiling opengl source code in Linux:
/tmp/ccXUFm6i.o(.text+0xf): In function display': : undefined reference toglClear’
/tmp/ccXUFm6i.o(.text+0x29): In function display': : undefined reference toglColor3f’
/tmp/ccXUFm6i.o(.text+0x36): In function display': : undefined reference toglBegin’
/tmp/ccXUFm6i.o(.text+0x4d): In function display': : undefined reference toglVertex3f’
/tmp/ccXUFm6i.o(.text+0x64): In function display': : undefined reference toglVertex3f’
/tmp/ccXUFm6i.o(.text+0x7b): In function display': : undefined reference toglVertex3f’
/tmp/ccXUFm6i.o(.text+0x92): In function display': : undefined reference toglVertex3f’
/tmp/ccXUFm6i.o(.text+0x9a): In function display': : undefined reference toglEnd’
/tmp/ccXUFm6i.o(.text+0x9f): In function display': : undefined reference toglFlush’
/tmp/ccXUFm6i.o(.text+0xb4): In function init': : undefined reference toglClearColor’
/tmp/ccXUFm6i.o(.text+0xc4): In function init': : undefined reference toglMatrixMode’
/tmp/ccXUFm6i.o(.text+0xcc): In function init': : undefined reference toglLoadIdentity’
/tmp/ccXUFm6i.o(.text+0xf5): In function init': : undefined reference toglOrtho’
/tmp/ccXUFm6i.o(.text+0x119): In function main': : undefined reference toglutInit’
/tmp/ccXUFm6i.o(.text+0x126): In function main': : undefined reference toglutInitDisplayMode’
/tmp/ccXUFm6i.o(.text+0x13b): In function main': : undefined reference toglutInitWindowSize’
/tmp/ccXUFm6i.o(.text+0x14a): In function main': : undefined reference toglutInitWindowPosition’
/tmp/ccXUFm6i.o(.text+0x15a): In function main': : undefined reference toglutCreateWindow’
/tmp/ccXUFm6i.o(.text+0x16f): In function main': : undefined reference toglutDisplayFunc’
/tmp/ccXUFm6i.o(.text+0x177): In function main': : undefined reference toglutMainLoop’
collect2: ld returned 1 exit status

from the very firsr opengl example form the redbook. here is the source anyways:

#include <GL/glut.h>
#include <GL/gl.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);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow(“hello”);
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

also all other code does the same thing. anyone may know why?

you need to link with the libraries, this is unique to your compiler so check the documentation

How are you calling the compiler, from a console window or a IDE like k-develope?

You need to tell the linker to include the openGL librarys, should look something like this: -lGL -lGLU -lglut

You also need to make sure you have installed the glut runtime library’s and developement librarys.
Redhat has them as a RPM installation file.

[This message has been edited by nexusone (edited 02-18-2004).]

thank you so much for help, ill look into it, I also got Slackware 9.1 which has the opengl libraries, because I found the header files.

still doesnt work, also all other programs that use libraries get the same error. still have no clue, compiling works, only linking doesnt.

how are you compiling
if you are using and IDE which is it?
if you are using a command line what is the exact line you type in?

im compiling using a terminal, and gcc like this:
gcc filename.c
if i compile using anjuta it compiles correctly so there is no syntax errors in the file, but when it tries to build it fails with the errors.
but i usully do it in terminal.
also today i was writting a source code which used the curses.h include file and that game me a bunch of same errors.
thank you…

Have you made doubly sure that you’ve install and linked them under gcc? I have found gcc to be an excellent compiler, but it’s as tempermental as a HollyWood Starlet.

im compiling using a terminal, and gcc like this:
gcc filename.c

Hehe, maybe it is not enough. As everybody here told you, try to add the libraries :

gcc filename.c -lGL -lGLU -lglut

If you can find the actual name of the lib, eg. libGL.so, just cut out the leading ‘lib’ and trailing ‘.so’
I do not remember for curses, try something like -lcurses

If it still does not work, maybe the lib*.so are located at a non-standard place, you can add the dir with a command switch: -L/usr/mydir . Find the lib*.so with a simple ‘locate filename’.

Good luck !

[This message has been edited by ZbuffeR (edited 02-22-2004).]

Hehe, yeah. I had to use the -L and -l to include the libraries…Thank you so much fopr help you guys.

Len