我正在尝试使用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;
我将不胜感激为什么我无法编译这个。我可以使用gcc -c
编译C文件并阅读我可以为Ada编译相同的方法。
答案 0 :(得分:4)
由于gcc仅识别.ads
和.adb
作为Ada源的文件结尾(如Eugene提到的here中所述),因此您需要明确告诉它您希望此文件为编译为Ada源。你可以通过
gcc -x ada -c Calculator.ada
编译器可能会发出类似
的警告Calculator.ada:11:11: warning: file name does not match unit name, should be "calc.adb"
但你可以忽略它。但是,最佳做法是使用gcc预期的文件名。
答案 1 :(得分:2)
默认情况下,Ada源文件需要以.ads
(对于包规范)或.adb
(对于实体)结束,文件名需要与它们包含的顶级实体匹配。在您的情况下,您应该使用calc.adb
。
如果您有更复杂的源文件包含多个实体,则可以使用gnatchop
tool to rename source files。
在File Naming Topics and Utilities下,本手册包含更多文档,说明如何在文件系统中表示源代码。