Estevez Cherie J DLVA wrote:
> I am having the same problem and tried putting -lglut last but it still came
> up with tons of undefined references to the gl functions. Any other ideas?
> Which version of the library should be used for linux ....".a", ".so",...I
It seems like 75% of the questions here are due to basic problems using
the linker. Maybe there needs to be a "How to Link with Mesa" FAQ list or
The Unix-ish command to link a program with libraries looks like this:
cc -I/path/to/mesa/includes myprogram.c -L/path/to/mesa/libraries -lfoo -lbar
The include files you need are "gl.h", "glu.h", etc., and the libraries you
need are "libGL.*", "libGLU.*", etc. If these files are in some "standard"
location known to your compiler (e.g. /usr/include, /usr/lib, /usr/X11R6/*,
etc.), then the -I... and -L... flags are not needed.
The -l... flags list the libraries to link to. The flag "-lfoo"
tells the linker to look for the library "libfoo.so" or "libfoo.a"
in the "standard" location, or in the location you specified with the
I believe most systems will attempt to link the shared library (libfoo.so)
before looking for the archive library (libfoo.a). Your linker may
have special flags to influence the choice. The shared library
may have a trailing version number (e.g. libfoo.so.2.2), and on some
systems (e.g. HP-UX) may use a ".sl" extension instead of ".so".
It's also possible to explicitly specify the libraries (shared or archive)
cc -I/path/to/mesa/includes myprogram.c /path/to/libfoo.a /path/to/libbar.a
The order of the libraries is, in general, very important, unless your
linker has some special options to deal with libraries which depend on
each other (e.g. on HP-UX "ld +n" or "cc -Wl,+n").
(With the HP-UX linker, if the libraries are all shared libraries, the order
doesn't seem to matter. Your linker may be different.)
The libraries must be specified in high-level to low-level order. GLU and
GLUT are built on top of OpenGL, which (when using the X driver) is built on
top of X11. Admittedly, it's not always obvious what libraries depend on
each other, so some know-how is necessary.
I generally use this library sequence:
cc myprogram.c -lglut -lGLU -lGL -lXll
If you need math functions like sin(), tan(), etc., the sequence
cc myprogram.c -lglut -lGLU -lGL -lXll -lm
If you need to link to Xt, Motif or some other windowing toolkit, it would
be something like:
cc myprogram.c -lglut -lGLU -lGL -lXm -lXt -lX11
Gregory Fruth (gregory.fruth@...)
The Aerospace Corporation
Los Angeles, CA