[Front] [Reference] [Imp. Guide] [Index]

Chapter 4: Compiling and Linking Programs
[Prev] [Next]

Table of Contents


[Up] Introduction

Table 4-1 contains a list of the subdirectories in the /opt/graphics/OpenGL directory. These subdirectories contain header files and libraries which may be used when compiling and linking your programs. They also include helpful sample source code.

Table 4-1: OpenGL Directories and their Content
Subdirectory This Directory Contains...
include/GL Header files needed for OpenGL development.
lib Several run-time shared libraries.
lbin Run-time executables.
doc OpenGL documentation including reference pages.
contrib/libwidget A Motif widget library and source code.
contrib/glut_samples Example OpenGL programs that are referenced in the OpenGL Programming Guide.
contrib/libglut Utilities found in the OpenGL Utility Toolkit as mentioned in the OpenGL Programming for the X Window System manual.
contrib/xglinfo Utility to print display and visual information for OpenGL with the X Window system.
contrib/glw_samples Source code for Motif widget sample programs.

[Up] Including Header Files

Most OpenGL programs and applications that only use the standard OpenGL data types, definitions, and function declarations, need only include the header file gl.h under the /opt/graphics/OpenGL/include/GL directory. Use the following syntax:
#include <GL/gl.h>
Still other header files may be needed by your program, depending on your application. For example, in order to use the OpenGL extension to X Windows (GLX) you must include glx.h, as shown below.
#include <GL/glx.h>
Instructions for including various additional header files are usually provided with the README file that accompanies the utility or function. The README also includes instructions for using or operating the utilities.

Your header file declarations at the beginning of your program should look similar to this:

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/gl.h>
#include <GL/glx.h>

[Up] Linking Shared Libraries

OpenGL is supported on workstations using shared libraries that must be linked with the application program.

When you compile your OpenGL programs, you must link the application with the OpenGL library libGL. Notice that the OpenGL library is dependent on the HP X extensions library (libXext).

An ANSI C compile line will typically look similar to this:

c89 program.c -I/opt/graphics/OpenGL/include \
  -L/opt/graphics/OpenGL/lib -lXext -lGL -lX11
Note that to compile your application using ANSI C, you can also use the cc command with either of the command line options +Aa or +Ae.

If you are going to compile your application using HP's ANSI C++ compiler or cfront C++ compiler, use one of the following commands:

aCC
[Up] used to compile an ANSI C++ application.

CC +a1
[Up] used to compile a cfront C++ application.
See the Graphics Administration Guide for more information on compiling.

This table summarizes the shared libraries and X11 directories that are linked on the command line example above.

Table 4-2: Shared Libraries
Library Description
libGL OpenGL routines
libX11 X11 routines
libXext HP X11 extensions

[Up] OpenGL Procedure Calls

In order to facilitate maximum performance, the OpenGL library uses a unique procedure calling convention. This convention is currently supported only by the HP C and C++ compilers which are available in conjunction with the Workstation ACE for HP-UX 10.20 (July 1997) OpenGL developers package.

If you get a large number of "Undefined pragma" messages (for example, Undefined pragma "HP_PLT_CALL" ignored) when compiling an OpenGL application, you are most likely using a compiler that does not support this new calling convention. To get an appropriate HP C or C++ compiler, you will need to contact your local HP Sales Representative.

You must also include the gl.h header file supplied with HP's implementation of OpenGL in any source code that makes OpenGL calls. If you have unresolved OpenGL symbols (for example, "Unsatisfied symbol glVertex3f") when linking your application, make sure that the correct gl.h file is being included in all your source files. Any gl.h files from other vendors or other sources will not work with HP's implementation of OpenGL.

[Prev] [Up] [Next]
[Front] [Reference] [Imp. Guide] [Index]