9 Compiling and Linking with the Error Message Service

There are three Fortran include files available for use with the Error Message Service: SAE_PAR, EMS_PAR and EMS_ERR (see Appendix E 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:

Equivalent header files are installed in /star/include for use in C code which is calling EMS – they are named sae_par.h, ems_par.h and ems_err.h. In addition, ems.h contains the function prototypes for each of the C functions. The syntax

  #include "sae_par.h"
  #include "ems.h"

should be used within the C code, and the compiler option -I/star/include used when compiling C and Fortran code.

The Error Message Service is included automatically when programs are linked using the ADAM application linking commands, alinketc.

To link a non-ADAM Fortran program with the the Error Message Service, the command line would be something like:

  % f77 -I$STARLINK_DIR/include program.f -L$STARLINK_DIR/lib ‘ems_link‘ \
        -o program.out

The command to compile and link a C program might be:

  % cc -o program -I$STARLINK_DIR/include -L$STARLINK_DIR/lib program.c \

Note that the commands used to invoke the C and Fortran compilers vary from one UNIX implementation to another (indeed, there may be more than compiler of each type on the same machine).

If the C program makes no use of the EMS Fortran interface, the ‘ems_link‘ command may be changed to ‘ems_link Conly‘. This will avoid the linker looking for the Starlink CNF library, which may not be present at a non-Starlink site.