22 Compiling and Linking Software that Uses AST

 22.1 Accessing AST Include Files
 22.2 Linking with AST Facilities
 22.3 Building ADAM Applications that Use AST

A small number of UNIX commands are provided by AST to assist with the process of building software. A description of these can be found in Appendix E and their use is discussed here. Note that in order to access these commands, the appropriate directory (normally “/star/bin”) should be on your PATH.40

22.1 Accessing AST Include Files

The include files provided for use with Fortran are:


Declares the types of all AST functions and defines parameter constants, except those that identify error values.

Defines parameter constants to represent the various error values to which the AST error status may be set when an error occurs (§4.13).

References to AST include files should be in upper case. Most modern Fortran compilers allow the directory to be specified as a command line option:

  f77 prog.f -I/star/include -o prog

If you are using such a compiler then your Fortran source code should, for instance, include:


(that is, there is no need to include the directory within the INCLUDE statement). If your compiler does not provide such an option then your source code must contain an absolute file name identifying the directory where the include files reside, for instance:

        INCLUDE ’/star/include/AST_PAR’

22.2 Linking with AST Facilities

Fortran programs may be linked with AST by including execution of the command “ast_link” on the compiler command line. Thus, to compile and link a program called “prog”, the following might be used:

  f77 prog.f -L/star/lib ‘ast_link‘ -o prog

On Linux systems you should usually use g77 -fno-second-underscore in place of f77 - see “Software development on Linux” in SUN/212.

Note the use of backward quote characters, which cause the “ast_link” command to be executed and its result substituted into the compiler command. An alternative is to save the output from “ast_link” in (say) a shell variable and use this instead. You may find this a little faster if you are building software repeatedly during development.

Programs which use AST can also be linked in a number of other ways, depending on the facilities they require. In the example above, we have used the default method which assumes that the program will not be generating graphical output, so that no graphics libraries need be linked. If you need other facilities, then various switches can be applied to the “ast_link” command in order to control the linking process.

For example, if you were producing graphical output using the PGPLOT graphics package, you could link with the AST/PGPLOT interface by using the “pgplot” switch with “ast_link”, as follows:41

  f77 prog.f -L/star/lib ‘ast_link -pgplot‘ -o prog

again using g77 -fno-second-underscore in place of f77 on Linux systems.

See the “ast_link” command description in Appendix E for details of the options available.

22.3 Building ADAM Applications that Use AST

Users of Starlink’s ADAM programming environment (SG/4) on UNIX should use the “alink” command (SUN/144) to compile and link applications and can access the AST library by including execution of the command “ast_link_adam” on the command line, as follows:

  alink adamprog.f ‘ast_link_adam‘

Note the use of backward quote characters.

By default, AST error messages produced by applications built in this way will be delivered via the Starlink EMS Error Message Service (SSN/4) so that error handling by AST is consistent with the inherited status error handling normally used in Starlink software.

Switches may be given to the “ast_link_adam” command (in a similar way to “ast_link”—§22.2) in order to link with additional AST-related facilities, such as a graphics interface. See the “ast_link_adam” command description in Appendix E for details of the options available.

40If you have not installed AST in the usual location, then substitute the appropriate directory in place of “/star” wherever it occurs.

41Use the “pgp” option instead if you wish to use the Starlink version of PGPLOT which uses GKS to generate its output.