Installing Gnat and an Ada Environment
Overview
- 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
installing the
recommended compiler (ie gnat) and the recommended environments, which are:
- AdaGIDE
- Gnatbench: An Eclipse plugin
- GPS
- Command Line - using a windows or linux command window or using ssh
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
here
Recommended compiler: Gnat
- A free self-installing Windows executable is available at
https://libre.adacore.com/
- A brief registration is required
- 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
gnatmake
(ie the command to compile a program) will work
- Hint 2: If you are have problems using gnat under Vista, see
this page
- Linux systems:
- On Debian bases systems (eg Ubunte) 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 and compile sources for gnat and gps directly from AdaCore.
AdaGIDE
Eclipse
- The Eclipse plugin Gnatbench is available from
https://libre.adacore.com/
under the GNAT GPL folder
- Remember to select the correct processor (eg x86-windows)
- 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
then Gnatbench Ada Development Guide/Before You Begin in Eclipse
Help
- Information on using on using Gnatbench can be found on
this page
GPS
- GPS is automatically installed when you install the gnat compiler
(GNAT GPL Edition 2007)
from
https://libre.adacore.com/
- Linux systems: See instructions above on Gnat for information on installing GPS
Installing Secure Shell or PuTTY
- One way to run using a command line is to access rucs from your home
machine using Secure Shell
or
PuTTY
- Telnet sessions are no longer allowed to access rucs
Recommended Editors
- 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
file
- 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
- 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
syntax enable
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
are below.
- 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
the after directory.
On your home machine, and assuming you installed vim in
folder c:\program_files go to the c:\program files\vim,
and if the subfolder vimfiles does not exist, create it.
Then create subfolders vimfiles\after and vimfiles\after\ftplugin,
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.
Getting Started with 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
foo.adb,
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");
end proj1;
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
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
this:
- Either add the following lines to you
.vimrc file:
let g:ada_default_compiler="gnat"
let g:mapleader="\\"
- Or, follow
these instructions.
- For vim 7.0 (and probably earlier),
to be able to compile by using the command
:make,
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
ada.vim and
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