How to include the NAG C library on unix machines

First we need a source code to test. The NAG libraries are stored in /opt/NAG*, where you can find the shared libraries (*.so) and the static libraries (*.a), include files, as well as example source code, data and results. To get started, copy some source code from the NAG C library, which is contained in the folder /opt/NAGgnu/cll6a08dgl, to your home directory

cp /opt/NAGgnu/cll6a08dgl/examples/source/d02race.c ~/.

To compile the code, we need the include directory, and the lib directory. The compile command is then

cd ~
c++ -I/opt/NAGgnu/cll6a08dgl/include d02race.c -L/opt/NAGgnu/cll6a08dgl/lib -lnagc_nag

In order for the program to run, we need to include the location of the library in our runtime path. To do this on the university system you need to edit the .cshrc file found in your home directory. From a terminal type:

cd ~
emacs .cshrc &

and add the following line under "Set your aliases HERE"

setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/opt/NAGgnu/cll6a08dgl/lib

Open up a new terminal and the program should run! Just type a.out from your home directory.



Other HowTos on unix...


Return to Homepage