Ada

ADA Programming Language – Starting Point

Introduction
Despite the fact that this language is not (yet) really popular among developer’s world, Ada and it’s strongly typed and Object-Oriented structure make of this 80’s language a powerful and modern algorithmic application for educational purposes.
I will not try to convinced you that this language is better than another one since, i believe that, each language have it’s own and dedicated purpose. I just want to introduce it to you…if you are open to it.
So why such article ? because as a beginner in this language, i would love to found a single place to start from ground zero to “Hello World”.

Audience
Your a student in software engineering or developer (any stage) and want to discover a language that will bring to the sky !

Requirements
Come with your favorite Linux distribution and a few hours of your time.

Installation

  • Fedora 14
    [root@nowin ~]# yum install gcc-gnat xmlada gtkada gnatcoll
    [root@nowin ~]# gnatmake --version
    GNATMAKE 4.5.1 20100924 (Red Hat 4.5.1-4)
    Copyright (C) 1995-2010, Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.
    There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  • Debian Squeeze
    [root@nowin ~]# apt-get install gnat
    [root@nowin ~]# gnatmake --version
    GNATMAKE 4.4.5
    Copyright (C) 1995-2008, Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.
    There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

“Hello World”
Here a step by step explaination of the compilation:

    1. Create a project directory

[me@nowin ~]# mkdir testada
[me@nowin ~]# cd testada

    1. Create source code

There is 2 types of source code files
.ads Specification file
.adb Body file
In here we don’t need a specification file.

[me@nowin testada]# vim helloworld.adb
and paste the code

with Ada.Text_IO; use Ada.Text_IO;
procedure HelloWorld is
begin
Put_Line("Hello World from GNAT!");
end HelloWorld;

Save and exit from vim

    1. Compile the source code and create object code

Now compiling:
[me@nowin testada]# gnatmake -c helloworld.adb
gcc -c helloworld.adb

If everything is ok it will generate 2 files:
helloworld.ali “Ada Library Information” file
helloworld.o Object file

Notes:
If the name of the procedure/package do not match the name of the .adb file(not case sensitive) you will get the following output (to raise the error i removed an “l” from Hello in the procedure name):
gcc -c helloworld.adb
helloworld.adb:2:11: warning: file name does not match unit name, should be "heloworld.adb"

    1. Link the object code and creating a executable file

First bind the projetct, it make some check and prepare for link program.
[me@nowin testada]# gnatbind helloworld
it will generate 2 files
b~helloworld.ads
b~helloworld.adb

Then Link files to build the executable:
[me@nowin testada]# gnatlink helloworld

    1. Run the executable program

Should be something like… 😉
[me@nowin testada]# ./helloworld
Hello World from GNAT!

Notes:

    • With Gnatmake, Gnatbind, Gnatlink command line you can omit the file extention
    • Step 3 and 4 can be merge into one single command line

[me@nowin testada]# gnatmake helloworld
gnatbind -x helloworld.ali
gnatlink helloworld.ali

  • See gnatmake –help for more compilation option

You want more ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: