### 22 Compiling and Linking Software that Uses 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 the “ast.h” Header File

The “ast.h” header file defines the external interface to the AST library, including all constants, function prototypes, macros, etc.. It should usually be include into a C source file using the statement:

#include "star/ast.h"

The header file is usually stored within the directory “/star/include/star” and should be located using the usual compiler options for finding C include files, for instance:

cc prog.c -I/star/include -o prog

This is preferable to specifying the file’s absolute name within your software.

Note, the default installation procedure places a copy of “ast.h” into both “/star/include” and “/star/include/star”. This is for the benefit of legacy software that expects to find the AST header file in “/star/include” rather than “/star/include/star”. The installation of “ast.h” into “/star/include” can be disabled at build-time by specifying the “–without-topinclude” option when running the configure script.

#### 22.2 Linking with AST Facilities

C programs which use AST facilities may be linked by including execution of the command “??link

” on the compiler command line. Thus, to compile and link a program called “prog”, the following might be used:

cc prog.c -L/star/lib ‘ast_link‘ -o prog

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

cc prog.c -L/star/lib ‘ast_link -pgplot‘ -o prog

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

#### 22.3 Building ADAM Applications that Use AST

” on the command line, as follows:

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