문제

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

도움이 되었습니까?

해결책

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!

다른 팁

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.

You have to assign execute permission on your executable :

$ chmod a+x hello

and run it:

$ ./hello
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top