Hello World in Ada

Our first program will print the classic “hello world” message. Here’s the full source code.

with Ada.Text_IO; use Ada.Text_IO;

procedure Hello_World is
begin
    Put_Line ("hello world");
end Hello_World;

To run the program, compile the code into an executable using gnatmake.

$ gnatmake hello_world.adb
$ ./hello_world
hello world

Sometimes we’ll want to build our programs into binaries. In Ada, the gnatmake command handles both compilation and linking.

First, compile the code:

$ gnatmake hello_world.adb
$ ls
hello_world   hello_world.adb   hello_world.o   hello_world.ali

We can then execute the built binary directly.

$ ./hello_world
hello world

Now that we can run and build basic Ada programs, let’s learn more about the language.