Setting up the Ada programming environment is the first step to start coding in Ada. This guide will walk you through the process of installing the necessary tools and configuring your development environment.

  1. Choosing an Ada Compiler

There are several Ada compilers available, but the most commonly used and recommended for beginners is the GNAT (GNU NYU Ada Translator) compiler, which is part of the GNU Compiler Collection (GCC).

Popular Ada Compilers:

  • GNAT: Part of GCC, widely used and well-supported.
  • ObjectAda: A commercial Ada compiler.
  • Rational Rhapsody: Another commercial option.

For this course, we will focus on GNAT.

  1. Installing GNAT

Windows

  1. Download GNAT Community Edition:

  2. Run the Installer:

    • Follow the on-screen instructions to install GNAT.
    • Ensure that the installer adds GNAT to your system's PATH.

macOS

  1. Install Homebrew (if not already installed):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Install GNAT:

    brew install gnat
    

Linux

  1. Using Package Manager:

    • For Debian-based systems (e.g., Ubuntu):
      sudo apt-get update
      sudo apt-get install gnat
      
    • For Red Hat-based systems (e.g., Fedora):
      sudo dnf install gcc-gnat
      
  2. Verify Installation:

    gnat --version
    

  1. Setting Up an Integrated Development Environment (IDE)

While you can write Ada code in any text editor, using an IDE can significantly enhance your productivity. Here are some popular options:

GNAT Studio

  1. Download GNAT Studio:

  2. Install GNAT Studio:

    • Follow the on-screen instructions to install GNAT Studio.
  3. Configure GNAT Studio:

    • Open GNAT Studio.
    • Go to Edit > Preferences.
    • Set the path to the GNAT compiler if it is not automatically detected.

Visual Studio Code

  1. Install Visual Studio Code:

  2. Install Ada Language Support:

    • Open Visual Studio Code.
    • Go to the Extensions view by clicking the Extensions icon in the Activity Bar on the side of the window.
    • Search for "Ada" and install the Ada Language Support extension.
  3. Configure Ada in Visual Studio Code:

    • Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on macOS).
    • Type Preferences: Open Settings (JSON) and add the following configuration:
      {
        "ada.gnatPath": "/path/to/gnat"
      }
      

  1. Verifying the Setup

To ensure everything is set up correctly, let's compile and run a simple Ada program.

Example: Hello World

  1. Create a new file named hello.adb and add the following code:

    with Ada.Text_IO; use Ada.Text_IO;
    
    procedure Hello is
    begin
       Put_Line("Hello, World!");
    end Hello;
    
  2. Compile the Program:

    gnatmake hello.adb
    
  3. Run the Program:

    ./hello
    

You should see the output:

Hello, World!

Conclusion

You have successfully set up your Ada programming environment. You installed the GNAT compiler, set up an IDE, and verified the installation by compiling and running a simple Ada program. In the next section, we will dive into writing your first Ada program in more detail.

© Copyright 2024. All rights reserved