Installing Gnat and an Ada Environment
- For your home machine you will need a compiler and an environment for creating,
compiling, and running programs
- The instructions that follow give information on
recommended compiler (ie gnat) and the recommended environments, which are:
- Gnatbench: An Eclipse plugin (not tested)
- Command Line - using a windows or linux command window or using
to connect to rucs, with an editor (eg vim) to create your file and with
gnatmake to compile. More details are below.
Information on using these systems can be found
Recommended compiler: Gnat
- A free self-installing Windows executable is available at
- Support for other OS's is also available at this site. Instructions for them
- Remember to select the correct processor (eg x86-windows (64 bits))
- Download size: roughly 300MB
- The download includes a full compiler as well as a number of tools, include
GPS (an IDE) and SPARK (for proving program properties).
- Installation instructions for different OS can be found in file README.txt on the download page.
- Another source for gnat for many platforms is www.getadanow.com.
The version available here is typically older, but it has a less restrictive license.
Installing the AdaCore GNAT compiler on Mac
- Thanks to Dr. Barland for these instructions.
To verify your PATH: in a new Terminal window, running which gnatmake should
report (something like) /Users/username/opt/GNAT/2018/bin/gnatmake).
Download the installer .dmg from adacore.com/download
(named something like “gnat-community-2019-20190523-x86_64-darwin-bin.dmg”)
To run the installer: it will first fail due to being an untrusted download. After that, select
System Preferences » Security and Privacy » General
and choose “run anyway”.
Note: Use the default install-location, or another location inside your home directory.
(I had problems if I installed the gnat tools in /usr/local/ or other more traditional locations.)
As mentioned by the installer, add the path “/Users/username/opt/GNAT/2019/bin” (or, whatever path you specified toinstaller)
to your PATH inside a startup script such as ~/.cshrc.
To find out your command line shell, type in ps and look for either bash, csh, or tcsh and follow
the appropriate instructions below. These commands only take effect in newly opened windows.
Important: It may be necessary to install Xcode from the app store before gnat will work on a
Compiling and Running on Macs
- You can compile and run using the command line
- You may need to use ./gnatmake to run the compiler
- Mac Editors: Do NOT use an editor that produces .rtf files.
- Mac IDEs:
- GPS: To run GPS, simply enter gps. (If you get a missing library error
you may be able to fix the problem by first installing XQuartz.)
Once you have GPS running you will need to create a
project for your program.
More instructions on using GPS are below and here.
- JGrasp : this IDE apparently has an
install package for Macs. It should work after gnat is installed.
Apparently you can edit and compile with textmate,
which has an Ada bundle. I don't know if gnat needs to be installed
separately to make the textmate Ada bundle works. After compiling with
textmate, to get input redirection, you may need to run your program
from the command line. (If you find an option to redirect input from
within textmate, please let me know.)
Installing the GNAT compiler on Linux
- To get the latest compiler you must install the one from AdaCore
- On Debian bases systems (eg Ubuntu) you can use the
APT package manager to install gnat and GPS, as follows
(assuming that 4.3 is the current version of gnat):
< apt-get install gnat-4.3
< apt-get install gnat-gps
You can also download binary files for gnat and
gps directly from AdaCore.
- If you do this, then you should be able to
follow the the instructions above for the mac (with a few
obvious changes for linux rather than mac osx).
- Another simplest GUI environment to use to create your program is jGRASP
- You can download jGRASP from
- Downloads are available for PC, Mac, Linux
- The Eclipse plugin GNATbench is available from
by clicking "More packages ", then selecting x86 Windows, 2015 from the platform dropdowns, and then
- Not tested recently
- GNATbench is not listed under all processors.
- Mac: the GNATbench zip file under x86-windows contains a jar file for mac osx.
It may allow you to use GNATbench on the mac. If you get it to work, please let me
- If you get an error that says that the program could not execute the
make command, then you may need to also install the make program
found under the TOOLS
folder. More information on how to install it can be found in the Eclipse
help system by selecting
Help/Help Contents in Eclipse and
Gnatbench Ada Development Guide/Before You Begin in Eclipse
- Information on using on using Gnatbench can be found on
- GPS is automatically installed when you install the gnat compiler
(GNAT GPL Edition 2007)
- Linux systems: See instructions above on Gnat for information on installing GPS
Getting Started with GPS Project Files
- Here are simple instructions on using a gnat project file
Assume that you want your project to contain a single ada source file called
and that you want this to be your main program.
- Create a project file called, for example,
proj1.gpr with these contents:
project proj1 is
for Main use ("foo");
Compile your program with the command
gnatmake -P proj1
You can specify lots more information (such as directories and compiler options) in the project file
Installing PuTTY to Access Rucs
- One way to run using a command line is to access rucs from your home
which you can download and install
- Important: to access rucs using putty you must be authenticated on campus
or be running a VPN client.
- Secure shell (ssh)
would also work, but apparently they no longer offer a free version.
- It used to be possible to access rucs via a telnet session, but this is
no longer allowed
- Other ways to accss rucs include the following:
- Running ssh from windows command window or windows powershell
- Running ssh from mac terminal window
- When working on the command line, you will need an editor
- Recommended editors include the following:
Configuring Vim for Ada
- Vim can be configured so that it automatically indents ada programs, does
syntax coloring, and so that the command :make will run gnatmake on your
- To configure vim you should change your vim startup file
- What is the vim startup file called?
- On windows it is usually _vimrc
- On unix/linux it is .vimrc (although, if vim can't find
.vimrc it will use _vimrc)
- Where is your vim startup file?
- On windows this will it will typically be in the vim install directory (eg
c:\program files\vim) or in $HOME
- Hint: You can get vim to display the name of the
startup file that it used by
running vim and entering the command :echo $MYVIMRC
- On unix it's normally found in your home directory (ie $HOME)
- Add the following lines in your vim startup file
(first create this file if it doesn't already exist):
filetype indent on
filetype plugin on
Note: These options may be set by default on rucs
After you have created completed the configuration,
you might want to try the following suggestions:
- In your vim startup add the line
"noremap ; :" so that
commands can be started by typing ; rather than :. This is faster and easier.
- After using :make you can move to the current/next/previous
error using the commands :cc, :cn, :cp
Configuring Vim to Enable :make
- The :make command: When vim is configured correctly, you can use
the :make command to compile your program.
After doing the :make command, the vim commands :cc, :cn, :cp will go to the
current, next, and previous syntax error.
- In department labs and on rucs, vim should be configured
so that these commands work correctly.
- Instructions for configuring your home machine so that vim can use :make and :cc
- Unfortunately, in versions 7.1 and 7.2 of vim,
the :make command is configured so that vim needs a project file when it compiles ada program.
Using project files is simple, but it is an extra step.
Instructions on using them are in a slide following this section.
The instructions below
tell how to configure vim to compile ada programs using :make without having a project file.
They also tell how to configure vim's
error format so that the commands :cc, :cn, and :cp work correctly.
- To use make without a project file and to use :cc, you need to reset the make command
and the error format. Here are
instructions to do this:
- A simple solution is to execute these commands from within vim:
:set makeprg=\ %
:set errorformat=%f:%l:%c:\ %m,%f:%l:%c:\ %tarning:\ %m,%f:%l:%c:\ (%ttyle)\ %m
However, if you want to put these commands in your vim startup to avoid
typing them every time you start vim, it won't work
because the ada mode configuration files will override them.
To have these two set commands automatically take effect, you must put them
commands in a location where they will be executed
after the configuration files are read and executed.
This can be done by putting a file containing them in a directory in
On your home machine, and assuming you installed vim in
c:\program_files go to the
and if the subfolder
vimfiles does not exist, create it.
Then create subfolders
and in this subfolder create the file
ada.vim. In this
file put the lines
set makeprg=\ %
set errorformat=%f:%l:%c:\ %m,%f:%l:%c:\ %tarning:\ %m,%f:%l:%c:\ (%ttyle)\ %m
Now restart vim and you are done.
Test this by creating a program that has some syntax errors
and doing :make. After the make command, the cursor should jump to the the first syntax error.
If there are more errors, the commands :cn and :cp should jump to the next and previous error.
You can split a window showing all of the errors with :copen. Use split window commands
to go back and forth between the error window and the regular window. You can close the error
window with the command :cclose in the window or with the command :only in the source code window.
Final Note: If you like to have smartcase enabled, you should also put :set
smartcase in your after/filetype/vim.ada file.
Configuring Earlier Versions of Vim for Ada
- To configure earlier versions of vim (ie earlier than 7.2) you should follow
the above steps, and do the appropriate one of the following:
- Vim 7.1 has an error in the Vim mode that causes many error
messages to appear when vim edits an Ada file. There are two ways to fix
- Either add the following lines to you
- Or, follow
For vim 7.0 (and probably earlier),
to be able to compile by using the command
do the following:
- Create the directory (ie folder)
.vim in your home directory
(ie H:\ drive)
- In the directory .vim, create the subdirectory ftplugin
- In the directory ftplugin, edit the file
add the lines
set makeprg=gnatmake\ %
set autowrite " if you want automatic saves prior to compiling
set tabstop=4 " my preference for tabs
set shiftwidth=4 " my preference for shifts