Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ada Packages

149 views
Skip to first unread message

George

unread,
Sep 17, 2011, 1:45:27 AM9/17/11
to
Hi All,

I tried to build a basic package. My two files look like this:

File 1: basic_num_io.ads

package Basic_Num_IO is
procedure Num_IO;
end Basic_Num_IO;

File 2: basic_num_io.adb

with text_io; use text_io;

package body Basic_Num_IO is
procedure Num_IO is
package Integer_InOut is new Integer_IO(integer);
package Float_InOut is new Integer_IO(float);
begin
null;
end Num_IO;
end Basic_Num_IO;

If I call gnat compile basic_num_io.ads I get the error message:

basic_num_io.ads:8:01: end of file expected, file can have only one
compilation unit

What am I doing wrong? Where can I find it in the documentation?

Kind regards

George

Jeffrey Carter

unread,
Sep 17, 2011, 2:15:03 AM9/17/11
to
On 09/16/2011 10:45 PM, George wrote:
>
> If I call gnat compile basic_num_io.ads I get the error message:
>
> basic_num_io.ads:8:01: end of file expected, file can have only one
> compilation unit

basic_num_io.ads clearly has at least 8 lines in it, not the 3 you presented.
Since I don't know what's in this file, I can't really help you. Make sure this
file only contains the package specification.

In general, you don't need to compile the package specification; that's done
automatically when you compile the body.

gnatmake basic_num_io.adb

should do that for you, once you get the contents of the files correct.

> What am I doing wrong? Where can I find it in the documentation?

The documentation depends on which version of GNAT you're using. Documentation
for GNAT GPL 2011 is at

http://www.adacore.com/category/developers-center/reference-library/documentation/

--
Jeff Carter
"I'm a kike, a yid, a heebie, a hook nose! I'm Kosher,
Mum! I'm a Red Sea pedestrian, and proud of it!"
Monty Python's Life of Brian
77

J-P. Rosen

unread,
Sep 17, 2011, 2:16:30 AM9/17/11
to
Le 17/09/2011 07:45, George a écrit :
> I tried to build a basic package. My two files look like this:
>
> File 1: basic_num_io.ads
>
> package Basic_Num_IO is
> procedure Num_IO;
> end Basic_Num_IO;
>
[...]
> basic_num_io.ads:8:01: end of file expected, file can have only one
> compilation unit
>
Hmmm... It complains at line 8, but what you show has only 3 lines.
There must be something else that you didn't notice at the end of the
file, and the compiler considers that something as a second compilation
unit in the same file.

--
---------------------------------------------------------
J-P. Rosen (ro...@adalog.fr)
Adalog a déménagé / Adalog has moved:
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00

Georg Maubach

unread,
Sep 17, 2011, 3:18:20 AM9/17/11
to
Hi Jeffrey,
Hi Jean-Pierre,

you're right: I left my comments out.

I started all over, deleted both files and build a new file with just the
three lines in it:

package Basic_Num_IO is
procedure Num_IO;
end Basic_Num_IO;

The compiler error is now

gcc-4.3 -c basic_num_io.ads
cannot generate code for file basic_num_io.ads (package spec)
to check package spec for errors, use -gnatc
gnatmake: "basic_num_io.ads" compilation error

I tried gcc-4.3 -c -gnatc basic_num_io.ads. No error occured.

How can I fix that?

Kind regards

George

Simon Wright

unread,
Sep 17, 2011, 3:42:15 AM9/17/11
to
Georg Maubach <ada_re...@gmx.de> writes:

> gcc-4.3 -c basic_num_io.ads
> cannot generate code for file basic_num_io.ads (package spec)

As someone above pointed out, GNAT won't generate object code from a
spec (unless the spec doesn't need, ie must not have) a body. Try
compiling the .adb file.

-gnatc is "Check syntax and semantics only (no code generation)". I
found this out using the command "gnatmake -h".

You're better off using gnatmake as the compiler driver, it understands
all about dependencies and the Ada bind/link process, and will produce
executables if it can.

Georg Maubach

unread,
Sep 17, 2011, 3:46:14 AM9/17/11
to
Hi Jeffrey,
Hi Jean-Pierre,

I tried again and checked my code. The reason for the error is a wrong
call to a function. It should read

package Float_InOut is new Float_IO(Float);

instead of

package Float_InOut is new Integer_IO(Float);

Many thanks for your willingness to help.

Kind regards

George
0 new messages