This chapter discusses how to compile Ada programs using the gcc command, and the command line switches that can be used to control the behavior of the Ada compiler.
The first step in creating an executable program is to compile the units of the program using the gcc command. You must compile the following files:
the body file (.adb) for a library level subprogram or generic subprogram
the spec file (.ads) for a library level package or generic package that has no body
the body file (.adb) for a library level package or generic package that has a body
You need not compile the following files
the spec of a library unit which has a body
because they are compiled as part of compiling related units. ERC32 Ada compiles generic units when a client instantiates the generic, specs when the corresponding body is compiled, and subunits when the parent is compiled. If you attempt to compile any of these files, you will get one of the following messages (where Filename is the name of the file you compiled):
No code generated for file Filename (package spec) No code generated for file Filename (subunit)
The basic command for compiling a file containing an Ada unit is
$ erc-coff-gcc -c [switches] filename
where filename is the name of the Ada file (usually having an extension .ads for a spec or .adb for a body). You specify the -c switch to tell gcc to compile, but not link, the file. The result of a successful compilation is an object file, which has the same name as the source file but an extension of .o and an Ada Library Information (ALI) file, which also has the same name as the source file, but with .ali as the extension. ERC32 Ada creates these two output files in the current directory, but you may specify a source file in any directory using an absolute or relative path specification containing the directory information.
gcc is actually a driver program that looks at the extensions of the file arguments and loads the appropriate compiler. For example, the GNU C compiler is cc1, and the Ada compiler is gnat1. These programs are in directories known to the driver program, but need not be in your path. The gcc driver also calls the assembler and any other utilities needed to complete the generation of the required object-code files.
It is possible to supply several file names on the same gcc command. This causes gcc to call the appropriate compiler for each file. For example, the following command lists three separate files to be compiled:
$ erc-coff-gcc -c x.adb y.adb z.c
calls gnat1 (the Ada 95 compiler) twice to compile x.adb and y.adb, and cc1 (the ANSI C compiler) once to compile z.c. The compiler generates three object files x.o, y.o and z.o and the two ALI files x.ali and y.ali from the Ada compilations. Any switches apply to all the files listed, except for -gnatx switches, which apply only to Ada compilations.