running Ada program in linux terminal
Asked Answered
K

3

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

Klayman answered 16/1, 2013 at 13:51 Comment(1)
"./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.)Nerta
A
8

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!
Anacreontic answered 16/1, 2013 at 15:2 Comment(6)
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).Stithy
Thanks @trashgod! executing on home directory ~ worked..! But how to change permission and execute from the current directory ?Klayman
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.Anacreontic
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.Klayman
Ah, I see. The media directory may include other mounted file systems; more here. I'd be wary, but you could look at the x permissions of the intermediate directories.Anacreontic
@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.Klayman
N
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.

Nereus answered 16/1, 2013 at 14:41 Comment(1)
I'm guessing that GNAT did do the +x, but one of the directories in /media/disk1/ada\ programs lacks the required permission.Anacreontic
O
2

You have to assign execute permission on your executable :

$ chmod a+x hello

and run it:

$ ./hello
Obstetrics answered 16/1, 2013 at 14:13 Comment(3)
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.Nerta
"chmod a+x hello" doesn't work..! :( getting same permission denied error.Klayman
most likely the directory is on a partition that is mounted with noexec. you can't execute anything from that.Bloodroot

© 2022 - 2024 — McMap. All rights reserved.