For previewing animation:
to include some of the more important include files.#include <GL/gl.h> /* for OpenGL */ #include <GL/glu.h> #include <GL/glut.h> /* for GLUT */ #include "gd.h" /* for GD2 */
-lgd -lpng -lz -ljpeg -lfreetype -lm -lglut -lGLU -lGL
A quick tutorial on UNIX libraries: Subroutine libraries come in two forms, .a files and .so files. When you make an executable, subroutines are ``linked'' to the main program. If you compile with -lfoo, the compiler by default looks for the archive file libfoo.a, and if it doesn't find it, it looks for the shared object file libfoo.so. These files are searched for in the list of directories given in -L options to the C/C++ compiler, then in the directories listed in the shell variable $LD_LIBRARY_PATH, then in the default directory /usr/lib. See "man ld" for more details. When an archive file (.a) is linked, the appropriate subroutines from the object files (.o) are copied, making your executable larger, but ensuring that it will always run (on the right architecture). When a shared object file (.so) is linked, the subroutines are not copied and compile/link time. Instead, at run time, the system uses LD_LIBRARY_PATH to find the .so file and the appropriate subroutines are dynamically linked into your executable in memory. This results in much smaller executable files, but it means that if you copy your executable to another machine without copying all of the .so's it references, your program won't run. The upshot of this is that LD_LIBRARY_PATH must be set correctly or something is likely to fail.
If you experience errors from missing .so files, you'll need the command
It's a good idea to put this command in your .login. You can, of course, check this variable withsetenv LD_LIBRARY_PATH /usr/lib:/usr/local/lib
You can get a list of shared object files that a given executable needs with ldd <PROGRAM>.
If your machine is running OSX, you'll need to install Fink or DarwinPorts, install GD2, and add /opt/local/bin to your path. OSX uses a different header namespace than Linux, you you'll need to replace the includes mentioned above with
and use the following link sequence (split into two lines for readability only):#include <OpenGL/gl.h> /* for OpenGL */ #include <OpenGL/glu.h> #include <GLUT/glut.h> /* for GLUT */ #include "/opt/local/include/gd.h" /* for GD2 */
You'll then be able to compile the app, and run it via the X11 server found at /Applications/Utilities/X11.app-L/opt/local/lib -lgd -lpng -lz -ljpeg -lfreetype -lm -L/System/Library/Frameworks/OpenGL.framework/Libraries -L/System/Library/Frameworks/GLUT.framework/ -lGLU -lGL -framework GLUT