Ada 95 Short Tutorial

Creating a project

To use IDE you must first install properly GNAT binaries, utilities and setup environment variables. First, you must create a new project to work. For this, press  button in C-Forge main window.

You'll get the dialog very similar to next one.

Enter the name of project, select type of the Revision Control.

Press the 'OK' button.

Creating a first target

The Create new target(s) dialog will be appear.

Here you can enter the name of first target in this project - let it be test_ada. Select Type for this target to 'Ada executable'.

Press 'OK' button and you'll get your project window.

Adding a sources into the project

Now, here is only one target in project. Move cursor selection to this target and press  button to add source file to this target. This target will be buld from test_ada.adb (main program its basename must be equal to target) and package ada_package.adb + ada_package.ads, Note, that ada_package.ads must have Type - 'Ada header' and  Add as Include mark checked:

Press the OK button. If, you'll change the orientation of views (Ctrl-Alt-O), your project should looks like this:

Changing all sources

Select all sources and headers, using Ctrl. And drag and drop them (using Mouse button 2) to Working Area. At this moment the working copies and RCS locks for these files will be created. Icons of all sources should appear in the Working Area.

All files should be placed in the Editor Window.

Now lets modify the source files as follows:

test_ada.adb:

with Ada_package;
with Text_IO; use Text_IO;

function Test_ada return integer is
begin
        Put_Line("Hello from Gnat_test !");
        Ada_package.Hello;
        Put_Line("Goodbye from Gnat_test !");
        return 1;
end Test_ada;

ada_package.adb:

with Text_IO; use Text_IO;

package body Ada_package is
     procedure Hello is
     begin
          Put_Line("Hello from Gnat_test !");
     end Hello;
end Ada_package;

ada_package.ads:

package Ada_package is
     procedure Hello;
end Ada_package;

The entry point of this target is in the test_ada.adb file. This code is putting line "Hello from Gnat_test !", then call a procedure 'Hello' from package 'Ada_package', and puts the goodby text. The package 'Ada_package' consists from one procedure 'Hello' which is putting the greeting string.

The view of Ada source in Editor Window is shown at the next image. Note, that all code is indenting automatically, you are don't need to indent sources by hands.

Building and executing the target

Save files in all editors, move the cursor to target and press  button to compile this target. The next project log window will be poped up:

If there are some errors in source files - in log window will be 'red' (errors) and/or 'cyan' (warning) lines: double click on them will popup corresponding source on error line.

Now double click on target - it will be executed, with the following output in project log:

Creating second target

Now let's create a yet one target in this project. Press the  button in the Project Desktop toolbar. When Create new target(s) dialog is appear enter the name of new target (for example new_test) and make sure that target Type is selected to 'Ada executable'.

Move cursor to new target and add the source file with the boby of new target, using the 'Add source' button - . When this source is appear in the Dependency Tree, drag'n'drop it to the Working Area. Type in it the following code:

new_test.adb:

with Ada_package;
with Text_IO; use Text_IO;

function New_test return integer is
begin
     Put_Line("Hello from New_test !");
     Ada_package.Hello;
     Put_Line("Goodbye from New_test !");
     return 1;
end New_test;

There is call to procedure 'Hello' from package 'Ada_package' - for proper compiling of this example we need to add this package in dependency tree of new target. To do so - move cursor selection to the ada_package.adb in the Dependency Tree and holding Ctrl+Shift keys Drag'n'Drop it (using mouse button 2) to new target, like this:

The file icon of file ada_package.adb will be appear in dependency of new_test.

And now, lets make this target using Drag'n'Drop. To do it - move the icon of target from Dependency Tree to the 'Make drop site' as shown below:

To execute new target also double click on it.