Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running Ada program in linux terminal

Tags:

linux

ada

gnat

I use Linux mint. Installed gnat to work with Ada programs, using "sudo apt-get install gnat".
created a simple hello world program:

with Ada.Text_IO;
procedure Hello is
begin
    Ada.Text_IO.Put_Line("Hello, world!");
end Hello;

and saved it as "hello.adb"

Tried running it from the location it was saved, opened terminal and typed & got following:

$ cd /media/disk1/ada\ programs
$ gnatmake hello.adb
gcc-4.4 -c hello.adb
gnatbind -x hello.ali
gnatlink hello.ali
$ hello
The program 'hello' can be found in the following packages:
* hello
* hello-debhelper
Try: sudo apt-get install
$ ./hello
bash: ./hello: Permission denied

What shall i do to see the output of the program?
where does it go wrong?

Few websites said, to just type "hello" after "gnatmake hello.adb" but it didn't work,
and few said, to try "./hello" after "gnatmake hello.adb" but that too didn't work?

what next? help out pls..

like image 344
jithhtharan Avatar asked Jan 16 '13 13:01

jithhtharan


People also ask

What is Ada in Linux?

Ada is a structured, statically typed, imperative, and object-oriented high-level programming language, extended from Pascal and other languages.

How do you write Hello World in Ada?

Put_Line ("Hello, World!" Put_Line ("Hello, World!"


2 Answers

Don't build in /media/disk1/ada\ programs, a directory where you (apparently) don't have adequate permission. Instead, build somewhere in your home directory, ~, where you do have permission. GNAT executables are typically installed in /usr/bin, which is probably already in your PATH.

$ which gnatmake
/usr/bin/gnatmake
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ cd ~
$ gnatmake hello
gcc-4.6 -c hello.adb
gnatbind -x hello.ali
gnatlink hello.ali
$ ./hello 
Hello, world!
like image 127
trashgod Avatar answered Sep 21 '22 05:09

trashgod


Your compilation process is fine. As Marc C says, you normally don't need to care about the execution permission (the chmod command). GNAT should take care of this.

To execute your program, you can't just type hello. It is a new program: you've just made it, and actually your terminal is too dumb to understand what you mean. You have to tell him where your program is in the file system. That's the point of typing ./hello. Basically, it means "look for a program called hello in the current directory". Consequently, it won't work if you've moved in another directory.

like image 35
tvuillemin Avatar answered Sep 21 '22 05:09

tvuillemin