Linking to libADA programs

Most of my programs are written in C (or rather, a nasty combination of C and C++) and use my libADA library. I started to write this library a couple of years ago to keep some basic data analysis routines easily available. I haven't really done very much with it since then, but it does provide a nice interface to the CPGPLOT graphics routines.

Before you try to compile or run the programmes, you need to set a few environment variables. If you're running things alot, it might be worth sticking them in your .tcshrc

setenv PGPLOT_DIR /home/fclarke/pgplot
setenv PGPLOT_ENV /xwin
setenv LD_LIBRARY_PATH /home/fclarke/lib:$LD_LIBRARY_PATH

In order to compile my programmes, you will need a two stage compile line (unless a makefile is included);

gcc -O -c -I/home/fclarke/include filename.c

where filename is the name of the source file. This should compile the source code (filename.c) to object code (filename.o). If there is more than one source file, simply list them all at the end of the compile line.

Next, you must link the object code to the libraries. Because of the way PGPLOT works, you have to use a Fortran compiler to do this. I find that g77 works best;

g77 -o filename filename.o -L/home/fclarke/lib -lada -lcpgplot -lpgplot -L/usr/openwin/lib -lX11

Again, if you have more than one object file, simply add them in after filename.o. This should produce an executable with the name "filename". Sometimes however, for reasons I haven't yet worked out, the linker seems to very sensitive to the order of the libraries (-lxxx commands). Often, if a program won't link, changing the order of the libraries (and then changing them back!) will fix it!!.