Schemer
Schemer

Reputation: 137

Compilation with GNATColl

I have installed GNAT 2018 (64 bits) on a PC Windows 8.1. GNATColl seems well present and compiled through repertories :

C:/GNAT/2018/include/gnatcoll
C:/GNAT/2018/lib/gnatcoll.static

I try to compile this small test program :

with Ada.Text_IO;       use Ada.Text_IO;
with GNATCOLL.Terminal; use GNATCOLL.Terminal;
procedure Test_Colors is
   Info : Terminal_Info;
begin
   Info.Init_For_Stdout (Auto);
   Info.Set_Color (Standard_Output, Blue, Yellow);
   Put_Line ("A blue on yellow line");
   Info.Set_Color (Standard_Output, Style => Reset_All);
   Put_Line ("Back to standard colors -- much better");
end Test_Colors;  

with the command :

gnatmake -gnat12 -gnatf -O3 "Test_Colors.adb" -aIC:/GNAT/2018/include/gnatcoll  -aLC:/GNAT/2018/lib/gnatcoll.static

The file Test_Colors.ali is well created but then the binding goes wrong :

gnatbind -aIC:/GNAT/2018/include/gnatcoll -aOC:/GNAT/2018/lib/gnatcoll.static -x test_colors.ali
gnatlink test_colors.ali -O3
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x46d): undefined reference to `gnatcoll_get_console_screen_buffer_info'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x4f6): undefined reference to `gnatcoll_terminal_has_colors'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x6c6): undefined reference to `gnatcoll_get_console_screen_buffer_info'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x729): undefined reference to `gnatcoll_terminal_has_colors'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x73d): undefined reference to `gnatcoll_terminal_has_colors'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x9f3): undefined reference to `gnatcoll_set_console_text_attribute'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0xc93): undefined reference to `gnatcoll_set_console_text_attribute'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0xfb4): undefined reference to `gnatcoll_set_console_text_attribute'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x1372): undefined reference to `gnatcoll_set_console_text_attribute'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x23e): undefined reference to `gnatcoll_beginning_of_line'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x28e): undefined reference to `gnatcoll_clear_to_end_of_line'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x2d8): undefined reference to `gnatcoll_terminal_width'
collect2.exe: error: ld returned 1 exit status
gnatlink: error when calling C:\GNAT\2018\bin\gcc.exe
gnatmake: *** link failed.
Compilation échouée.

Do you know what to do to use successfully GNATColl ?

Upvotes: 0

Views: 368

Answers (2)

Simon Wright
Simon Wright

Reputation: 25501

Jacob’s project file will indeed build (assuming you have your source in a subdirectory \src and are happy with having your executable in \bin), but this one is a lot simpler:

with "gnatcoll";
project Test_Colors is
   for Main use ("test_colors.adb");
end Test_Colors;

The other options he shows will be extremely useful as you develop more advanced projects.

Upvotes: 1

Jacob Sparre Andersen
Jacob Sparre Andersen

Reputation: 6611

Use a project file and gprbuild. Something along these lines:

with "gnatcoll";

project Colors is
   for Languages use ("Ada");

   for Main use ("test_colors.adb");

   for Source_Dirs use ("src/");
   for Object_Dir  use "obj/";
   for Exec_Dir    use "bin/";

   package Builder is
      for Default_Switches ("Ada")
        use ("-m",
             "-s");
   end Builder;

   package Compiler is
      for Default_Switches ("Ada")
        use ("-fstack-check", --  Generate stack checking code (part of Ada)
             "-gnata",        --  Enable assertions            (part of Ada)
             "-gnato13",      --  Overflow checking            (part of Ada)
             "-gnatf",                     --  Full, verbose error messages
             "-gnatwa",                    --  All optional warnings
             "-gnatVa",                    --  All validity checks
             "-gnaty3aAbcdefhiklnOprstux", --  Style checks
             "-gnatyM125",                 --  Style checks
             "-gnatwe",                    --  Treat warnings as errors
             "-gnat2012",                  --  Use Ada 2012
             "-Wall",                      --  All GCC warnings
             "-O2");                       --  Optimise (level 2/3)
   end Compiler;

end Colors;

Now you can build your program with the command:

gprbuild -j0 -p -P colors.gpr

If you don't have any other project files in the directory you run the command from, it is even simpler:

gprbuild -j0 -p

Upvotes: 1

Related Questions