compile opengl & glut in linux redhat

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?

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.


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.

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
void reshape(int w, int h)
glViewport(0,0, w, h);
glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
int main(int argc, char **argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow(“Example 1”);
init(); //THIS IS NOT A GLUT FUNCTION! However, by convention, many
return 0;

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/ undefined reference to glXBindChannelToWindowSGIX' /usr/lib/ undefined reference toglXCreateContextWithConfigSGIX’
/usr/lib/ undefined reference to glXGetFBConfigAttribSGIX' /usr/lib/ undefined reference toXGetExtensionVersion’
/usr/lib/ undefined reference to XFreeDeviceList' /usr/lib/ undefined reference toXQueryDeviceState’
/usr/lib/ undefined reference to XListInputDevices' /usr/lib/ undefined reference toglXQueryChannelDeltasSGIX’
/usr/lib/ undefined reference to glXChannelRectSyncSGIX' /usr/lib/ undefined reference toglXChannelRectSGIX’
/usr/lib/ undefined reference to XFreeDeviceState' /usr/lib/ undefined reference toXOpenDevice’
/usr/lib/ undefined reference to glXQueryChannelRectSGIX' /usr/lib/ undefined reference toglXGetFBConfigFromVisualSGIX’
/usr/lib/ undefined reference to XmuLookupStandardColormap' /usr/lib/ undefined reference toXSelectExtensionEvent’


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).]

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]#

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.

Usually libraries have names like: 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.