Consider a slightly more complicated example with three files: a main program and the spec and body of a package:
package Greetings is procedure Hello; procedure Goodbye; end Greetings; with Ada.Text_IO; use Ada.Text_IO; package body Greetings is procedure Hello is begin Put_Line ("Hello WORLD!"); end Hello; procedure Goodbye is begin Put_Line ("Goodbye WORLD!"); end Goodbye; end Greetings; with Greetings; procedure Gmain is begin Greetings.Hello; Greetings.Goodbye; end Gmain;
Following the one-unit-per-file rule, place this program in the following three separate files:
spec of package Greetings
body of package Greetings
body of main program
Note that there is no required order of compilation when using GNAT.
In particular it is perfectly fine to compile the main program first.
Also, it is not necessary to compile package specs in the case where
there is an accompanying body; you only need compile the body. If you want
to submit these files to the compiler for semantic checking and not code
generation, use the -gnatc
switch:
$ gcc -c greetings.ads -gnatc
Although you can do the compilation in separate steps, in practice it’s
almost always more convenient to use the gnatmake
or gprbuild
tools:
$ gnatmake gmain.adb