How to Compile Ada Programs

This page briefly explains how to use your Ada compiler to create Ada programs.

The basic steps to commanding an Ada compiler are the same for all Ada compilers, but the details (the exact keys you press) vary from compiler to compiler. The basic steps are:

  1. Install the Ada compiler
  2. Create a project (directory)
  3. Create and edit file(s) containing Ada source code
  4. Compile the source code, creating object code
  5. Link the object code, creating a program
  6. Run the resulting program
  7. (Optionally) Debug the resulting program

For Ada compilation systems with graphical front-ends, every step but the first is usually obvious from the menus. However, if you're not using a graphical front end these steps may not be so obvious. Below are each of these steps, with some specific guidance for the GNAT and Rational VADS compilers when used without a graphical front-end (especially for MS-DOS/MS-Windows and Unix platforms).

  1. Install the compiler. These are very compiler-specific, but installation instructions are included with every compiler. Most operating systems have a ``PATH'' that must be correctly set up as part of the installation procedures.
  2. Create a project (directory). Generally it's best to create a separate directory for your Ada files. In MS-DOS and Unix, the command "mkdir" may be used to create a new directory. Rational VADS requires that a directory for Ada files be specially prepared; use the "a.mklib" command to do this.
  3. Create and edit file(s) containing the Ada source code. Use your favorite text editor to create Ada source code files (such as emacs, vi, edit, or Brief).
    1. Rational VADS requires all Ada filenames to end with ".a"; I suggest naming files in the form hello_spec.a and hello_body.a.
    2. GNAT is very picky about filenames. Filenames must have the same name as the compilation unit before the period. Also, filenames must end in ".ads" if they are specifications and ".adb" if they are bodies.
    No matter what compiler you're using, use a separate file for each different compilation unit (GNAT requires this).
  4. Compile.
    1. Rational VADS' compilation command is "ada FILENAME"
    2. GNAT's compilation command is "gcc -c FILENAME"
  5. Link.
    1. Rational VADS' link command is:
      ada -M main_program_name -o object_file_name
    2. GNAT's compilation command is:
      gnatbl -o object_file_name main_program_name.ali
  6. Run. This is generally done by typing in the name of the object file created.
  7. (Optionally) Debug. Rational VADS' debugger is called "a.db". GNAT's debugger is the normal gcc debugger "gdb".

Hopefully, at this point you can compile simple programs using your compiler. The best way to learn how to use your compiler is to read its introductory documentation; the information presented here is simply to help you get started.

If you're connected to the Internet, you can use WebAda to compile small Ada programs.

You can:

  1. Go to section 1.3.
  2. Go up to the Lovelace home page.

This page was last modified on 1-February-1995.

David A. Wheeler (