
All commands you must enter are given in this typeface. The computer's responses are shown in normal this typeface. You should go to a terminal, log in to hobbes, and follow this handout, step-by-step.
csstud@hobbes:11: cd csci51then trying:
csstud@hobbes:12: cp programs51/hello.adb . csstud@hobbes:13: cat hello.adb WITH Ada.Text_IO; PROCEDURE Hello IS BEGIN -- Hello Ada.Text_IO.Put (Item => "Hello there. "); Ada.Text_IO.Put (Item => "We hope you enjoy studying Ada!"); Ada.Text_IO.New_Line; END Hello; csstud@hobbes:14:
csstud@hobbes:14: gcompile hello.adb Compilation of hello.adb started on Fri Jan 14 15:22:46 EST 2000 Compilation ended on Fri Jan 14 15:22:53 EST 2000If there were compilation errors, a message to that effect appears as well. The compiler produces a "listing file" which gives an "official" record of the compilation. If there were compilation errors, the messages occur interspersed with the lines of Ada.
You can see this file using cat or more; you can also print a hard (paper) copy of it in the usual way. Let's look at the listing file from our compilation:
csstud@hobbes:15: cat hello.lsb GNAT 3.12p1 (19990629) Copyright 1991-1999 Free Software Foundation, Inc. Compiling: hello.adb (source file time stamp: 1996-01-23 03:03:19) 1. WITH Ada.Text_IO; 2. PROCEDURE Hello IS 3. 4. BEGIN -- Hello 5. 6. Ada.Text_IO.Put (Item => "Hello there. "); 7. Ada.Text_IO.Put (Item => "We hope you enjoy studying Ada!"); 8. Ada.Text_IO.New_Line; 9. 10. END Hello;
The next step is to link the program. The linker requires a file with an .ali file type.
csstud@hobbes:16: glink hello.ali Linking of hello.ali started on Fri Jan 14 15:23:11 EST 2000 Linking ended on Fri Jan 14 15:23:15 EST 2000Finally, we execute the program. While neither GNAT nor Unix requires a particular file type for executables, our scripts give them an .exe file type, and so should you.
csstud@hobbes:17: gexecute hello.exe Hello there. We hope you enjoy studying Ada!You can execute a program any number of times without re-compiling.
csstud@hobbes:18: gexecute hello.exe Hello there. We hope you enjoy studying Ada!You can use Unix commands to see which program units you've compiled and linked.
csstud@hobbes:19: ls -l *.ali -rw-r--r-- 1 csstud user 727 Jan 14 15:22 hello.ali csstud@hobbes:20: ls -l hello.exe -rwxr-xr-x 1 csstud user 119556 Jan 14 15:23 hello.exeLet's try another program. We'll compile, link, and execute it, and then enter some "bad" data (alphabetic instead of integer). Note the exception "traceback" telling you in which line of your program the exception was raised.
csstud@hobbes:21: gcompile distance.adb Compilation of distance.adb started on Fri Jan 14 15:29:10 EST 2000 gcc: distance.adb: No such file or directory gcc: No input files Compilation ended on Fri Jan 14 15:29:10 EST 2000Oops! We forgot to copy the program!
csstud@hobbes:22: cp programs51/distance.adb . csstud@hobbes:23: gcompile distance.adb Compilation of distance.adb started on Fri Jan 14 15:29:29 EST 2000 Compilation ended on Fri Jan 14 15:29:36 EST 2000 csstud@hobbes:24: glink distance.ali Linking of distance.ali started on Fri Jan 14 15:29:47 EST 2000 Linking ended on Fri Jan 14 15:29:53 EST 2000 csstud@hobbes:25: gexecute distance.exe How many hours will you be driving (integer) ? XYZ raised ADA.IO_EXCEPTIONS.DATA_ERROR Trace Back Information Program Name File Name Line ------------ --------- ---- distance distance.adb 22Oops! We entered XYZ instead of a numerical value! Running the program again with correct data input will give a reasonable answer.
csstud@hobbes:26: gexecute distance.exe How many hours will you be driving (integer) ? 5 At what average speed (miles per hour, integer) ? 55 You will travel about 275 miles
csstud@hobbes:27: cp programs51/hello_name.adb . csstud@hobbes:28: turnin Project name ? just-a-test Turnin started; type exit to leave turnin. Script started, file is just-a-test.turnin script> csstud@hobbes:29: gcompile hello_name.adb Compilation of hello_name.adb started on Fri Jan 14 15:33:26 EST 2000 Compilation ended on Fri Jan 14 15:33:29 EST 2000 script> csstud@hobbes:30: glink hello_name.ali Linking of hello_name.ali started on Fri Jan 14 15:33:37 EST 2000 Linking ended on Fri Jan 14 15:33:40 EST 2000 script> csstud@hobbes:31: gexecute hello_name.exe Enter your first name, exactly 10 letters. Add spaces at the end if it's shorter.> Jennifer Hello Jennifer . We hope you enjoy studying Ada! script> csstud@hobbes:32: exit Script done, file is just-a-test.turnin csstud@hobbes:33The file just-a-test.turnin can be printed out to turn it in, and will remain in your file system until you remove it.
Enjoy CSci 51 and Ada 95 and GNAT!