PDA

View Full Version : compile opengl & glut in linux redhat



fran24
04-22-2003, 03:27 AM
im trying to compile opengl under linux, its my first time, but only i have undefined references...

gcc -L/usr/lib -I/usr/include -lGLU -lglut prueba.c -o prueba.o

what is the right way to compile this kind of of program?

mikael_aronsson
04-22-2003, 04:16 AM
Hi !

Try to add -lGL also, this is the OpenGL library, if it still doesn't work then check the order of the names (-lGLU -lglut -lGL) the gnu linker is picky about the order of the libraries.

Mikael

Deiussum
04-22-2003, 04:30 AM
If that still doesn't work, try posting exact errors. It makes it much easier to help you figure out what's wrong. Without them all we can do is guess... Though, in this case I'm guessing it's just because you didn't include the -lGL.

fran24
04-22-2003, 05:26 AM
the program:

#include <GL/glut.h>

void init();
void reshape(int w, int h);
void display();

void init()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT); //Clears the Framebuffer with the color
glFlush();
}
void reshape(int w, int h)
{
glViewport(0,0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(20,20);
glutInitWindowSize(400,400);
glutCreateWindow("Example 1");
init(); //THIS IS NOT A GLUT FUNCTION! However, by convention, many
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

THE COMPILE LINE:
gcc -L/usr/lib -I/usr/include -lGL -lGLU -lglut prueba.c -o prueba.o


the error:
cc1: warning: changing search order for system directory "/usr/include"
cc1: warning: as it has already been specified as a non-system directory
/usr/lib/libglut.so: undefined reference to `glXBindChannelToWindowSGIX'
/usr/lib/libglut.so: undefined reference to `glXCreateContextWithConfigSGIX'
/usr/lib/libglut.so: undefined reference to `glXGetFBConfigAttribSGIX'
/usr/lib/libglut.so: undefined reference to `XGetExtensionVersion'
/usr/lib/libglut.so: undefined reference to `XFreeDeviceList'
/usr/lib/libglut.so: undefined reference to `XQueryDeviceState'
/usr/lib/libglut.so: undefined reference to `XListInputDevices'
/usr/lib/libglut.so: undefined reference to `glXQueryChannelDeltasSGIX'
/usr/lib/libglut.so: undefined reference to `glXChannelRectSyncSGIX'
/usr/lib/libglut.so: undefined reference to `glXChannelRectSGIX'
/usr/lib/libglut.so: undefined reference to `XFreeDeviceState'
/usr/lib/libglut.so: undefined reference to `XOpenDevice'
/usr/lib/libglut.so: undefined reference to `glXQueryChannelRectSGIX'
/usr/lib/libglut.so: undefined reference to `glXGetFBConfigFromVisualSGIX'
/usr/lib/libglut.so: undefined reference to `XmuLookupStandardColormap'
/usr/lib/libglut.so: undefined reference to `XSelectExtensionEvent'


thanks!!

Deiussum
04-22-2003, 06:07 AM
Looks like it's missing the glx library. Some systems seem to need that added to the link line, some don't. I don't remember what the exact name of the library was, but try -lglx or -lGLX.

Edit: You might also need the xlib library for those functions like XOpen.

[This message has been edited by Deiussum (edited 04-22-2003).]

fran24
04-22-2003, 06:30 AM
thanks, but it doesn't find -lglx and -lGLX, any idea?

gcc -L/usr/lib -I/usr/include -lGL -lGLU -lglut -lGLX prueba.c -o prueba.o
cc1: warning: changing search order for system directory "/usr/include"
cc1: warning: as it has already been specified as a non-system directory
/usr/bin/ld: cannot find -lGLX
collect2: ld returned 1 exit status
[root@falonso pruebas]#

Deiussum
04-22-2003, 08:39 AM
Well... I said that might not be the right name. My cable modem seems to be down at home right now so I can't ssh into my home computer to look for the names of those libraries.

Take a look at the files in your library directory and maybe, just maybe, you'll be able to figure it out for yourself. http://www.opengl.org/discussion_boards/ubb/smile.gif

Usually libraries have names like:

libGL.so or libGL.a

When using the name for linking you don't include the lib portion. Directories you'd probably want to look in would be wherever the libraries for X are stored on your system.

There's also a utility you can use to find the libraries that other libraries depend on, but I just cannot remember what it was offhand. Do a google search and maybe it will turn that up.