用GCC编译Ada

Nik*_*son 1 gcc ada

我正在尝试使用编译该Calculator.ada文件gcc -c Calculator.ada并收到错误warning: Calculator.ada: linker input file unused because linking not done-我试图查找解决方案并下载可能会为我编译此文件的其他内容,但尚未弄清楚。

这里是Calculator.ada

--
-- Integer calculator program.  Takes lines of input consisting of
-- <operator> <number>, and applies each one to a display value.  The
-- display value is printed at each step.  The operator is one of =,
-- +, -, *, /, or ^, which correspond to assign, add, subtract, multiply
-- divide, and raise, respectively.  The display value is initially zero.
-- The program terminates on a input of q.
--
with Text_IO;
with Gnat.Io; use Gnat.Io;
procedure Calc is
   Op: Character;               -- Operation to perform.
   Disp: Integer := 0;          -- Contents of the display.
   In_Val: Integer;             -- Input value used to update the display.
begin
   loop
      -- Print the display.
      Put(Disp);
      New_Line;

      -- Promt the user.
      Put("> ");

      -- Skip leading blanks and read the operation.
      loop
         Get(Op);
         exit when Op /= ' ';
      end loop;

      -- Stop when we're s'posed to.
      exit when Op = 'Q' or Op = 'q';

      -- Read the integer value (skips leading blanks) and discard the
      -- remainder of the line.
      Get(In_Val);
      Text_IO.Skip_Line;

      -- Apply the correct operation.
      case Op is
         when '='      => Disp := In_Val;
         when '+'      => Disp := Disp + In_Val;
         when '-'      => Disp := Disp - In_Val;
         when '*'      => Disp := Disp * In_Val;
         when '/'      => Disp := Disp / In_Val;
         when '^'      => Disp := Disp ** In_Val;
         when '0'..'9' => Put_Line("Please specify an operation.");
         when others   => Put_Line("What is " & Op & "?");
      end case;
   end loop;
end Calc;
Run Code Online (Sandbox Code Playgroud)

对于无法编译此代码的任何帮助,我将不胜感激。我能够很好地编译C文件,gcc -c并且可以读取Ada的相同编译方式。

fly*_*lyx 5

由于gcc仅识别Ada源.ads并将其.adb作为Ada源的文件结尾(如Eugene 在此链接中所述),因此您需要明确告诉它您希望将此文件编译为Ada源。您可以通过

gcc -x ada -c Calculator.ada
Run Code Online (Sandbox Code Playgroud)

然后,编译器可能会给出警告,例如

Calculator.ada:11:11: warning: file name does not match unit name, should be "calc.adb"
Run Code Online (Sandbox Code Playgroud)

但是您可以忽略它。但是,最佳实践是使用gcc期望的文件名。