2017-09-25 259 views
1

我试图编译这个Calculator.ada文件使用gcc -c Calculator.ada并收到错误warning: Calculator.ada: linker input file unused because linking not done - 我试过寻找解决方案并下载其他东西,可能编译这个但我还没有想通出来呢....Ada - 用GCC编译Ada

这里是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

虽然没有编译,或者我错过了一些@EugeneSh。 ?我sitll只有.ada,不应该/已经产生了一个.o? – NikkiNelson

+1

鉴于[this](https://gcc.gnu.org/onlinedocs/gnat_ugn/Running-a-Simple-Ada-Program.html),ADA计划应该有一个扩展名“adb”或“ads”。这可能是'gcc'只是不明白它是一个ADA程序... –

+1

键入“gnat --version”...如果你得到“命令未找到”你的gcc安装不完整,你会有找到并安装它的Ada部分(通常是一个名为“gnat- ”的包,然后“gnatmake Calculator.adb”(重命名该文件!)应编译并链接它(及其所有依赖项) –

回答

2

默认情况下,Ada源文件需要以.ads(对于包规范)或.adb(对于实体)结尾,文件名需要与它们包含的顶层实体相匹配。在你的情况下,你应该使用calc.adb

如果你有更复杂的源文件包含多个实体,你可以使用gnatchop tool to rename source files

File Naming Topics and Utilities下,本手册包含了更多关于如何在文件系统中表示源代码的文档。

+0

我确实已经阅读过这篇文章,并将我的文件更改为:'Calc.adb'和试图以相同的方式编译 - 我现在/然后收到错误:'gcc:error:CreateProcess:No such file or directory' – NikkiNelson

+0

难道你的'gcc'没有ADA的支持吗?它并不明显 –

+1

它是'calc.adb'(小写)。关于'CreateProcess'错误,这很奇怪。这不是FSF GCC打印的东西。您使用的是AdaCore发行版吗? –

3

由于GCC只识别.ads.adb为Ada的源文件结尾(如由Eugene提到this link解释),你需要明确地告诉它,你想这个文件被编译为阿达源。您可以通过

gcc -x ada -c Calculator.ada 

编译器这样做会那么可能会给像

Calculator.ada:11:11: warning: file name does not match unit name, should be "calc.adb" 

警告,但可以忽略。但是,最佳做法是使用gcc预期的文件名。

+0

我现在收到'没有这样的文件'存在错误 – NikkiNelson

+0

那么你没有显示你的完整代码。你导入一个不标准的包'Text_IO'(只有一个'Ada.Text_IO'包)。该错误可能在该包的界面中,您需要显示其代码。 – flyx