0

I somehow cannot compile (neither run) my Ada code in GPS. I get an error:

cannot generate code for file random.ads (package spec)
gprbuild: *** compilation phase failed

The random.ads file looks like this:

with Ada.Numerics.Float_Random;
use Ada.Numerics.Float_Random;
package random is

   protected randomOut is
      procedure Inicializal;
      entry Parcel(
                randomout: out Positive;
                from: in Positive;
                to: in Positive := 1
               );
   private
      G: Generator;
      Inicializalt: Boolean := False;
   end randomOut;

   task print is
      entry write(what: in String);
   end print;

end random;

The .gpr file looks as follows:

project Default is
   package Compiler is
      for Default_Switches ("ada") use ("-g", "-O2");
   end Compiler;

   for Main use ("hunting.adb");

end Default;

What does this mean? How can I fix it? Thank you!

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
lte__
  • 7,175
  • 25
  • 74
  • 131

2 Answers2

5

You can't generate code for a package specification.

This is normal and expected.

You can compile the package body, random.adb, and generate code for it - but there's usually no need.

Just compile your main program, (or your test harness if you're unit testing) and let the compiler find all its dependencies.

(If it can't, either you haven't written them yet, or it's looking in the wrong place. If you need help with that, add relevant info to the question).

-2

The problem is caused by

   task print is
      entry write(what: in String);
   end print;

As any task is specified as a body, the compiler had trouble deciding: it had a body, that has to be compiled, in a spec file, which does not. Moving the task to the .adb file solved the issue.

lte__
  • 7,175
  • 25
  • 74
  • 131
  • 3
    This code is perfectly legal in a package spec. As @BrianDrummond said, the problem is that GPS is being asked to compile a spec that requires a body. It will do quite a few checks, but it can’t generate output code. You need to compile the body for that. – Simon Wright May 07 '16 at 15:26