PDA

View Full Version : Compiling Errors, why?



d3xtor
02-17-2004, 07:40 PM
I get these errors compiling opengl source code in Linux:
/tmp/ccXUFm6i.o(.text+0xf): In function `display':
: undefined reference to `glClear'
/tmp/ccXUFm6i.o(.text+0x29): In function `display':
: undefined reference to `glColor3f'
/tmp/ccXUFm6i.o(.text+0x36): In function `display':
: undefined reference to `glBegin'
/tmp/ccXUFm6i.o(.text+0x4d): In function `display':
: undefined reference to `glVertex3f'
/tmp/ccXUFm6i.o(.text+0x64): In function `display':
: undefined reference to `glVertex3f'
/tmp/ccXUFm6i.o(.text+0x7b): In function `display':
: undefined reference to `glVertex3f'
/tmp/ccXUFm6i.o(.text+0x92): In function `display':
: undefined reference to `glVertex3f'
/tmp/ccXUFm6i.o(.text+0x9a): In function `display':
: undefined reference to `glEnd'
/tmp/ccXUFm6i.o(.text+0x9f): In function `display':
: undefined reference to `glFlush'
/tmp/ccXUFm6i.o(.text+0xb4): In function `init':
: undefined reference to `glClearColor'
/tmp/ccXUFm6i.o(.text+0xc4): In function `init':
: undefined reference to `glMatrixMode'
/tmp/ccXUFm6i.o(.text+0xcc): In function `init':
: undefined reference to `glLoadIdentity'
/tmp/ccXUFm6i.o(.text+0xf5): In function `init':
: undefined reference to `glOrtho'
/tmp/ccXUFm6i.o(.text+0x119): In function `main':
: undefined reference to `glutInit'
/tmp/ccXUFm6i.o(.text+0x126): In function `main':
: undefined reference to `glutInitDisplayMode'
/tmp/ccXUFm6i.o(.text+0x13b): In function `main':
: undefined reference to `glutInitWindowSize'
/tmp/ccXUFm6i.o(.text+0x14a): In function `main':
: undefined reference to `glutInitWindowPosition'
/tmp/ccXUFm6i.o(.text+0x15a): In function `main':
: undefined reference to `glutCreateWindow'
/tmp/ccXUFm6i.o(.text+0x16f): In function `main':
: undefined reference to `glutDisplayFunc'
/tmp/ccXUFm6i.o(.text+0x177): In function `main':
: undefined reference to `glutMainLoop'
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?

chowe6685
02-17-2004, 07:59 PM
you need to link with the libraries, this is unique to your compiler so check the documentation

nexusone
02-18-2004, 06:32 AM
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).]

d3xtor
02-18-2004, 07:24 AM
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.

d3xtor
02-18-2004, 04:57 PM
still doesnt work, also all other programs that use libraries get the same error. still have no clue, compiling works, only linking doesnt.

chowe6685
02-18-2004, 05:07 PM
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?

d3xtor
02-19-2004, 04:29 AM
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....

c0d3Junk3Y
02-20-2004, 04:58 AM
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.

ZbuffeR
02-22-2004, 07:01 AM
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).]

d3xtor
02-22-2004, 11:55 AM
Hehe, yeah. I had to use the -L and -l to include the libraries....Thank you so much fopr help you guys.

Len http://www.opengl.org/discussion_boards/ubb/smile.gif