Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 

What's inside.

Account Management

E-mail

Hardware and Media

Network and Wireless

Offsite Access

Printing

Processes

Security and Passwords

Software and Tools

Systems Staff

Web Development

 

Help Home

IT Labs Home

 
 
 
 
 

 
  Home > Software and Tools > Open GL/Mesa Programming/GLUT

Open GL/Mesa Programming/GLUT

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.

Sample Program and basic compiling issues

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.

  • To add directorys to your include path you use -I(dir)
  • To add directorys to your library path you use -L(dir)
  • To add directorys to your runtime library path you use -R(dir) for Suns and -Wl,-rpath -Wl,(dir) for other machines
  • To add a shared library to your program you use -l(library) (shared libraries are denoted with a .so extension)
  • To add a static library to your program you just use the full path of the statlic library (static libraries are denoted with .a extensions)

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.

Locating directories you may need to include/link against

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

Samples

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

Compiling works but the program won't run

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 your still having problems please contact:

Useful OpenGL Links

 
The University of Minnesota is an equal opportunity educator and employer.
IT Labs Online Help