★ wanayoo — archive 1999 http://www.codeforge.com/tutorials/AdaTutorial.htmlNouvelle recherche | Portail wanayoo
C-Forge home Ada 95 "Hello World" Tutorial


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, project's author, description and comments.

Note, that for project will be created directory in 'Project Root' with the 'Name', appended by suffix "-prj". In given case it will be '/home/alx/gnat_test-prj/'.

Press the 'OK' button, and target dialog will be appear.



Here you can enter the name of first target in this project - stay it default.

Directory layout can be useful, if you want to separate source, include and object files. But for GNAT you need to disable check button "Use directory layout". If you enable it - jumps to editor from errors in log window would be unavailable.

Don't forget to change the type of this target - it might be 'Ada executable'.

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



Now, here is only one target in project. Move cursor selection to this target and press  button to add source file to this target.



The file, which you want to add, does not exist - press 'New File' button and enter the name of it: gnat_test.adb

Note, that name of main source file might be equal to target name, but with extension '.adb' - ADa Body file.

Add yet one source file - 'gnat_package.adb'. It will be example of package using.

Now, using the  button add header file for package with the name 'gnat_package.ads'. This is Ada specs file, it correspond to header files in C.

Headers files will be appear in special folder, because you don't need to compile specs; they are compiled when they are used.

After this work the tree of your project is looks like this:



Select all sources and headers, using Ctrl. And drag and drop them (using Mouse button 2) to Working Files Desktop. Example is shown at the next picture.



At this moment the working copies and RCS locks for these files will be created.



Edit main file gnat_test.adb by double clicking on it in Working Descktop:



This file is putting line "Hello from Gnat_test !", then call a procedure 'Hello' from package 'Gnat_package', and puts the goodby text.

The package file might look like this:



In this package only one procedure, which is puts yet one line.

For this package the spec file might be this:



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 is 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.

And now double click on target - it will be executed, with output in project log:



Now let's create a yet one new target using the  button. In shown dialog enter the name of new target (for example gnat_test2) and don't forget to change target type to 'Ada executable'.

Move cursor to new target and add source file with main procedure (gnat_test2.adb) using the  button. Drop this source to Working Desktop and edit like this:


>


There is call to procedure 'Hello' from package 'gnat_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 gnat_package.adb in dependency tree and simply Ctrl-Shift Drag'n'Drop it (using mouse button 2) to new target, like this:



The file 'gnat_package.adb' will be appear in dependency of 'gnat_test2'.

And now, lets make this target using Drag'n'Drop. To do it - move this target from dependency tree to 'Make drop site' as shown below:



To execute new target also double click on it.

 

 


Copyright © Code Forge, Inc. 1997-99. All rights reserved.


Last modified: Thursday, 30-Sep-1999 02:12:37 MDT