Reputation: 141
I'm a bit of an newb' to Ada. I see the following error when compiling a spec file on its own:
gcc -c shapes.ads
cannot generate code for file shapes.ads (package spec)
gnatmake: "shapes.ads" compilation error
The code works when it's build with the body and I can run a program that uses the package.
So what's the problem?
Upvotes: 2
Views: 2692
Reputation: 8522
This isn't really an error. (Yeah, I know it looks like one :-)
The way GNAT works is that the object code for a unit (package spec and body, and any "is separates") is placed in a single, ".o", object code file. So you get the object code file when you compile the body--the compilation of which automatically brings in the spec--but not the spec alone.
An exception is when the spec doesn't require a body, i.e., it contains no declarations, such as subprograms or tasks, that require bodies.
Upvotes: 3
Reputation: 1804
The .ads file only contains the specification of a package. If it requires a body, you can't compile it that way. You have to compile the .adb file.
Think of it like a C header (.h) file. You don't compile them either, only the .c files.
PS: you can use gnatmake, it should automatically resolve dependencies and compile what's needed.
Upvotes: 2