Main navigation | Main content
The majority of the systems today have OpenGL installed on them by default.
If not you can download Mesa. In General if your system supports OpenGL you should use that over using Mesa you will get better performance.
To link your OpenGL Programs you may need to link in extra include and library directorys. We have the following mesa-sample.c file so you can test things out.
Many people do not know the difference between library path and runtime library path. Basically the library path is used at compile time to find the librarys and the runtime library path is used when you run a program. So for your purposes you will want to add a directory to both of them if you need to. If you forget to set the runtime library path you can use the LD_LIBRARY_PATH environment variable and add the directory to that, this may mess up other programs that depend on LD_LIBRARY_PATH so you should avoid it whenever possible.
(back to top)If you get an error similar to:
cannot locate GL.h
you need to find the .h in question and then add a -I(dir) to your compile line. You can use:
locate GL.h
or you could goto some of the system directorys for header files and use find inside of them to locate your files.
Under solaris you probably want to look in /usr/include, /usr/openwin/include and /usr/local/include.
Under linux you probably want to look in /usr/include /usr/local/include /opt/local/include
(back to top)To get our sample program to compile you want a compile line similar to the following:
Linux: cc sample.c -lglut -lGL -lGLU -pthread -lm Solaris: gcc -osample sample.c /usr/openwin/lib/libglut.a -lGL -lGLU -lXmu -lX11 -lm
If you receive a problem with Undefined symbols, Try rearranging the order of the library's. We've found that they compiler is rather picky about the order they are linked in.
Example:
[10:35] ~/tmp(mein@jessica) % cc sample.c -I/soft/X11R6.3/include \
-L/soft/X11R6.3/lib \
-lGL -lglut -lGLU -lXext -lXi -lXmu -lX11 -lsocket -lm
collect2: ld returned 1 exit status
/usr/lib/old_ld:
The shared object /usr/lib/libsocket.so did not resolve any symbols.
You may want to remove it from your link line.
Unresolved:
glXQueryExtension
glXMakeCurrent
glXChooseVisual
glXCreateContext
glXIsDirect
glXDestroyContext
glXSwapBuffers
glXWaitX
We need to move -LMesaGL so that it comes after -lMesaglut and -lMesaGLU
To compile on a linux machine You will need a compile line similar to the following:
cc sample.c -I/soft/X11R6.3/include -L/soft/X11R6.3/lib \ -lMesaGL -lMesaglut -lMesaGLU -lXi -lXmu -lXext -lXt -lX11 -lICE -lSM -lm(back to top)
If you have a problem with Can't open file libglut.so: or Cannot successfully map soname, You need to add in runtime linking options.
To do this on a solaris machine You need to add -R/soft/X11R6.3/lib. So your compile line will look like this:
cc sample.c -I/soft/X11R6.3/include -L/soft/X11R6.3/lib \ -R/soft/X11R6.3/lib \ -lMesaglut -lMesaGLU -lMesaGL -lXext -lXi -lXmu -lX11 -lsocket -lm
To do this on an SGI machine you need to add -Xlinker -rpath /soft/X11R6.3/lib so it looks like this:
cc sample.c -I/soft/X11R6.3/include -L/soft/X11R6.3/lib \
-Xlinker -rpath /soft/X11R6.3/lib \
-lMesaglut -lMesaGLU -lMesaGL -lXext -lXi -lXmu -lX11 -lsocket -lm
If you are still having problems with undefined references try setting LD_LIBRARY_PATH to include /soft/X11R6.3/lib
setenv LD_LIBRARY_PATH /soft/X11R6.3/lib
This may cause problems with other programs so it should be used as a last resort.
If you're still having problems please contact operator [at] cs.umn.edu
(back to top)