I'm trying to compile this Calculator.ada file using gcc -c Calculator.ada and receive the error warning: Calculator.ada: linker input file unused because linking not done -- I've tried looking up solutions and downloading other things that may compile this for me but haven't figured it out yet....
Here is 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;
I would appreciate any assistance as to why I can't compile this. I'm able to compile C files fine with gcc -c and read that I can compile the same way for Ada.
Since gcc only recognizes .ads and .adb as file endings for Ada sources (as explained in this link mentioned by Eugene), you need to tell it explicitly that you want this file to be compiled as Ada source. You can do this via
gcc -x ada -c Calculator.ada
The compiler will then probably give a warning like
Calculator.ada:11:11: warning: file name does not match unit name, should be "calc.adb"
but you can ignore that. However, best practice would be to use the file names expected by gcc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With