Another compiling problem

I am just getting started, so apologies for what is probably a basic question. I am using Redhat Linux 7.2 with a Voodoo3 graphics card. I am trying to compile the very first example from the book “OpenGL for the X Window System”. (I am unfamiliar with how X windows works and fairly new to Linux). The line I type to compile the program is:

cc -o glxsimple glxsimple.c -lGL -lXext -lX11

The problem I have is that the linker (ld) fails to find the “Xext” library and also fails to find the “X11” library. Funnily enough, there is no problem with the actual OpenGL stuff eg it finds the “GL” library and so forth. This makes me think perhaps the X libraries are called something different under Redhat linux 7.2. Would that be the case, and if so, can you tell me what to modify my the references to “X11” and “Xext” to? Many thanks.

I think that the problem is that you didn’t specify the wright path for your librairies.
To do it :

>locate libX11
>locate libXext

the two commands gives you a path

first possibility, you had the two path (they may be the same) to your file


and execute the commande


which update you ld.cache.It specifies the place where your compiler must look for libraries.

Second possibility specify these path at the compiling time, for example :

-L/usr/X11R6/lib -lglut -lGLU -lGL -lX11 -lXmu -lXext -lXt -lXi

I hope it will help.

[This message has been edited by MPech (edited 03-31-2002).]

Thanks for your suggestions, but they did not seem to do the trick. When I typed “locate”, I discovered that I had all the libraries I need, however when I type out the long versions, for example, in trying to compile the glutsphere program, I end up with another strange error. As follows:

[root@localhost glutsphere]# cc -o glutsphere glutsphere.c -lglut -lGLU -lGL -L/usr/X11R6/include/X11/Xmu -L/usr/X11R6/include/X11/extensions/ -L/usr/X11R6/include/X11
glutsphere.c: In function main': glutsphere.c:49: warning: return type ofmain’ is not int' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../ undefined reference topow’
collect2: ld returned 1 exit status

This is using the actual code supplied by the book which downloaded off the net - so there are no typing mistakes. Any thoughts would be welcome. Thanks.

MPech is absolutley right, the remaining error is a math function so you need to add -lm. The warning explains itself but you can ignore it. You can also remove your -L to the include directories.

Thank you very much! Your advice worked. I do have one question though, which is, how to I get my compiler to automatically link in the /usr/X11R6/lib libraries (and other libraries). I have edited the file and there was already a reference to this directory. I have also run the ldconfig command. It does not seem to make a difference. Any ideas? Doesn’t matter if you cannot be bothered answering, I’m pretty happy to have got thus far.

Have a great day.

Have you tried the following command :


it must match the path specified in your file

if it doesn’t you must export it to your system.
I think it might be something like :

>LD_LIBRARY_PATH = /usr/X11R6/lib

try it. It worked on my system.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.