6 Compiling and Linking with MSG and ERR

There are five Fortran include files available for use with the Message and Error System: SAE_PAR, MSG_PAR, MSG_ERR, ERR_PAR and ERR_ERR. (See Appendix A for details of the symbolic constants which they define).

The Starlink convention is that the name in upper case with no path or extension is specified when including these files within Fortran code, e.g.

  *  Global Constants:
        INCLUDE ’SAE_PAR’
        INCLUDE ’MSG_PAR’

Equivalent header files are provided for use in C code which is calling MSG or ERR – all the required header files, including the function prototypes, may be included by including the file mers.h.

The syntax

  #include "sae_par.h"
  #include "mers.h"

should be used within the C code.

Assuming that the software has been installed in the standard way and /star/bin has been added to the environment variable PATH, soft links with these upper-case names pointing to the required file are set up in the user’s working directory by the the commands:

  % star_dev
  % err_dev

The ADAM version of MSG/ERR is included automatically when programs are linked using the ADAM application linking commands, alink etc. These will handle either Fortran or C code.

To compile and link a non-ADAM program with the stand-alone version of MSG/ERR, the command line would be, e.g.

  % f77 -o program program.f -L/star/lib ‘err_link‘

On platforms with shareable libraries, -L/star/lib might be replaced by -L/star/share.

If it is necessary to link explicitly with the ADAM version of MSG/ERR and any libraries which it uses (e.g. to produce a shareable library), the script err_link_adam is available in /star/bin. The link command might be:

  % ld -shared -o libmypkg.so.1.0 -L/star/share -lmypkg ‘err_link_adam‘

The compilation of C code should be used with the compiler flag -I/star/include. For example the command to compile a C program might be:

  % cc -c -I/star/include program.c

Note that the command used to invoke the C compiler varies from one UNIX implementation to another (indeed, there may be more than one C compiler available on the same machine) – you should therefore check this with your Site Manager before proceeding.

Because the MERS C interface calls Fortran routines it is also necessary to explicitly link with the required Fortran libraries, e.g.

  % cc program.o -L/star/lib ‘err_link‘ -lF77 -lm -o program.out

The naming and number of the Fortran libraries differs between UNIX machines and so it is advisable to check in the relevant Fortran documentation for further details.