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)
- This is a large download: 100MB
- The download includes a full compiler as well as a number of tools, include
GPS, a visual IDE.
- Hint 1: You may need to reboot before
(ie the command to compile a program) will work
- Hint 2: If you are have problems installing gnat under Vista, see
- Another source for gnat for many platforms is www.getadanow.com
Installing the AdaCore GNAT compiler on Mac
- Download and expand from www.adacore.com/download,
clicking on "More platforms ..." and then selectin
the appropriate version of gnat
- Apparently the 2013 darwin install does not work in Lion. You may need to
upgrade to Mountain Lion.
- In a terminal window, do the following:
- Check if you have a
make program installed
on your machine:
Navigate to the directory that contains a file called: doinstall
- Enter "which make". If this responds with a path that
ends in make (eg /usr/bin/make)
then you have make and you can go to step 2.
Otherwise, if it just gives you a
prompt back, then you do not have make.
- To get make: Open xCode, go to preferences (eg cmd-,). Click on
downloads tab, install the command line tools. Now, if you
do "which make" then it should give /usr/bin/make.
Enter: sudo mkdir /usr/local/gnat
- This should be the root of what you downloaded and expanded.
Enter: sudo ./doinstall
- You will have to enter your password
Update your path as needed for your shell
- You can accept the defaults by pressing
return and y as prompted
- Be patient, because this command will take a while
(eg 10 minutes)
(You should gnore the comment about the debugger.)
You should now be able to compile using the command gnatmake
- Update commands for bourne shell and c shell are given at the end of the doinstall.
- For bash you can use this command:
- To find out the shell command that you are running
you can do the command "ps" and see what shell process is
- You will have to update your path every time you open a terminal
window, or you will have to put a command to do this into the
appropriate rc file (probably .profile, but possibly .cshrc or .bash_profile)
- Yosemite users may need to set the following environment variable
(ie put this in your .profile):
- export MACOSX_DEPLOYMENT_TARGET=10.9
- Or you can add -mmacosx-version-min=10.9 to your compiler
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 package 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
- 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
- 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
- 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