首页 > 解决方案 > 用 GNATColl 编译

问题描述

我在 PC Windows 8.1 上安装了 GNAT 2018(64 位)。GNATColl 似乎很好地存在并通过曲目进行了编译:

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

我尝试编译这个小测试程序:

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;  

使用命令:

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

文件 Test_Colors.ali 创建良好,但随后绑定出错:

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.

您知道如何成功使用 GNATColl 吗?

标签: adagnat

解决方案


使用项目文件和gprbuild. 这些方面的东西:

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;

现在您可以使用以下命令构建程序:

gprbuild -j0 -p -P colors.gpr

如果您在运行命令的目录中没有任何其他项目文件,则更简单:

gprbuild -j0 -p

推荐阅读