Compile and Run Hello World
Options for Compilation and Execution
- On campus you will use the comiler GNAT,
a very high quality free compiler that is a component of the
GNU open source
-
Gnat is a compiler only. For the full cycle of editing, compiling, and
running your program, you will also need an IDE or an editor.
- In campus labs you will have three options for the IDE or editor:
- AdaGIDE - an easy to use IDE
- Gnatbench - An Eclipse Plugin
- GPS - a more complex and more powerful IDE
- Command Line (ie separate editor and compiler)
- Information on using each of these is below
- Information for installing these on your home machine are
.
hello.adb
- Here is a sample Ada program to compile and run, Hello World:
with ada.text_io; -- Tell compiler to use i/o library
use ada.text_io; -- Use library routines w/o fully qualified names
procedure hello is
begin
put("Hi 320");
end hello;
Filename: hello.adb
Using AdaGIDE
- AdaGIDE is a simple IDE
- It provides autocompletion and access to the gdb debugger
- AdaGIDE is Windows only
- Available on campus at: Start/Programs/RUCourseSW/CST/Ada IDE/adagide
- May not be available on machines with smaller hard drives
- Steps to create, compile, and run
- Create w/ File/New
- Enter program
- Save to file hello.adb with File/Save
- Compile with Compile/Build (F3)
- Run with Run/Execute (F4)
Using Gnatbench on Eclipse
- Use menu item
Project/Build Current Project
or Project Rebuild Current Project
to check for syntax errors
and generate executable code
- The Build All icon checks for syntax errors, but only seems to generate
executable code the first time it is used
- The
Project/Build All
and Project/Build
Project
menu items check for
syntax errors but don't generate executable code
- My experience with Eclipse is limited. If you can provide me with more
information on using Gnatbench, I'd appreciate it.
Using GPS
- GPS is a more complex and more powerful IDE
- It provides a powerful interface to the debugger and has identifier completion
- GPS has versions for Windows and Linux
- GPS is based on projects. A project is defined by a project file (eg
yourProj.gpr) which
contains information such as
- The files that are used by the project
- The directories where those files are stored
- Which file is the Main file (ie where execution begins)
- What compiler options are to be used during compilation
- Steps to create a project and to create, compile, and run a program file
- Run GPS: Start/Programs/RUCourseSW/CST/Ada IDE/GPL_2007/GPS
- On the startup screen,
select "Start with default project in directory:", set the directory where you want to store the
project, and press OK
- Create your program by selecting File/New and then entering the program.
- To get syntax highlighting and indenting when you first type your program,
you should save the (empty) file
so that GPS knows that this an Ada file. To save, use File/Save and save it as yourName.adb.
- Set your program as the main file by doing Project/Edit Project Properties and select the tab for
"Main files", and then select Add to add your file as the main program
- Compile your program with Build/Make/yourFile.adb
- Run your program with Build/Run
- If you want to rename your project, you can change the name under the
General tab of Project/Edit Project Properties, and then save the new project
file. The old project file will still exist.
Creating a new project with GPS
- Select "Creating a new project with wizard"
- Select Project/New Project
- Steps with the wizard (press "Forward" after each step, and watch your progress in the left panel):
- Select "Single Project"
- Choose a name for your project (eg project1) and the directory
where the project will be created (eg on your desktop)
-
The project will consist of a project file (eg project1..gpr, your
program (eg hello.adb), and the files that result from compilation (eg
hello.o, hello.ali, hello.exe)
- Accept the choice of the language Ada
- Accept the VCS screen
- Accept the default source directory (eg your deskop)
-
Enter the build directory (eg Desktop) - this is where .o, .ali, and
.exe files will appear. (You may press apply at this point or continue
with the remaining screens)
- Accept the blank "Main files" screen
- Accept the default "Naming scheme"
- Accept the default switches
Other IDEs
- is an interesting IDE that provides various visualizations of
your program. Handles Ada and Java.
Command Line
- To use the command line, you must first use an editor to create hello.adb:
- Possible editors include vim, gvim, jedit, pico, pfe, ...
- To compile hello.adb use this command:
gnatmake hello
- You can also say gnatmake hello.adb
- To run your program use this command:
hello
- On windows, the command hello.exe also works
How to get a Command Line Window
- On Windows you can create a command window with Start/Run/Cmd
- On Windows you can also start a secure shell session to rucs, as follows:
- Start a secure shell client: Start/RUNetwork/SSH Secure Shell/Secure Shell Client
- Start a session to rucs.radford.edu
- Linux machines: a terminal window provides a command line
- Linux machines can also run secure shell to connect to rucs, as follows: ssh rucs
- Macs: similar to above
Installing compilers at home
- Information on installing at home is .
Using a debugger
- Each of the environments (AdaGIDE, Eclipse, GPS, command line) has a way of using the
debugger with Ada.
- are some instructions.
Files Created by Compilation
- Gnatmake creates the following files
-
Library Information file (eg sayhi.ali): describes when compilation occurred and
any file dependencies
- Object file (eg sayhi.o):
contains non-executable machine code, but does not contain code
for library routines)
- Executable file (sayhi.exe in Windows, sayhi in linux): executable
machine code (all libraries are linked in)
- The .ali and .o files are not needed after the executable is
created.
阅读(1971) | 评论(0) | 转发(0) |