Error: cannot generate code for file random.ads (package spec)

我与影子孤独终老i 提交于 2019-12-25 09:49:08

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/37088800/error-cannot-generate-code-for-file-random-ads-package-spec

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!