5

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..

T.E.D.
  • 44,016
  • 10
  • 73
  • 134
jithhtharan
  • 53
  • 1
  • 4
  • 4
    "./hello" should have worked. What do you see when you do an "ls -l hello"? If the eXecutable flag isn't set, then there's something amiss in your Linux configuration. GNAT sees to it that flag is properly set unless something else is interfering with it. (I use gnat Ada on Mint as well, so it should all work fine.) – Marc C Jan 16 '13 at 14:14

3 Answers3

7

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!
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    It's probably a good idea to avoid using directory names with spaces in them, too (this is unlikely to be the cause of your problem, though). – Simon Wright Jan 16 '13 at 21:16
  • Thanks @trashgod! executing on home directory ~ worked..! But how to change permission and execute from the current directory ? – jithhtharan Jan 17 '13 at 14:44
  • Glad you got it working. You should be able to use `mkdir` in your home directory and `cd` into the new directory. The default permissions should let you build there just as well. – trashgod Jan 17 '13 at 16:02
  • Apologies @trashgod, It works fine in home directory. But want it to work on /media/disk1/ada\ programs ? what goes wrong there ? what should i do to make it run in that directory ? help pls... thanks in advance. – jithhtharan Jan 18 '13 at 14:41
  • Ah, I see. The `media` directory may include other mounted file systems; more [here](http://forums.linuxmint.com/viewtopic.php?f=47&t=121139). I'd be wary, but you could look at the `x` permissions of the intermediate directories. – trashgod Jan 18 '13 at 15:56
  • @trashgod, thanks again for the direction shown. Found the source for the issues that I faced, its because the drive in which am trying to execute is vfat format. Browsing on info to change permission for vfat drive to use the executables files. – jithhtharan Jan 19 '13 at 13:24
3

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.

tvuillemin
  • 1,148
  • 3
  • 10
  • 25
  • 4
    I'm guessing that GNAT _did_ do the `+x`, but one of the directories in `/media/disk1/ada\ programs` lacks the required permission. – trashgod Jan 16 '13 at 15:20
2

You have to assign execute permission on your executable :

$ chmod a+x hello

and run it:

$ ./hello
GioLaq
  • 2,489
  • 21
  • 26
  • 5
    You shouldn't have to manually do this. The gnatmake build process takes care of it unless something in the configuration is interfering with it. – Marc C Jan 16 '13 at 14:15
  • "chmod a+x hello" doesn't work..! :( getting same permission denied error. – jithhtharan Jan 17 '13 at 14:45
  • most likely the directory is on a partition that is mounted with noexec. you can't execute anything from that. – Rommudoh Jan 25 '13 at 08:28