GPRbuild:编译器开关被传递给链接器

GPRbuild: compiler switch being passed to linker

我正在为 ARM 构建一个简单的程序。 GPRbuild 输出如下:

gprbuild -p -P avocado_test.gpr (in directory: /home/rodeo/Projects/AvocadoTest)
Bind
   [gprbind]      run_avocado_test.bexch
   [Ada]          run_avocado_test.ali
Link
   [link]         run_avocado_test.adb
/opt/GNAT/arm-elf/bin/arm-eabi-ld: unrecognised emulation mode: cpu=cortex-m3
Supported emulations: armelf
gprbuild: link of run_avocado_test.adb failed
Compilation failed.

根据我在网上找到的信息,ld 有一个开关 -m,它指定了一种仿真模式。但是,我没有在项目的链接器中使用此开关。不过,我 am 在编译器中使用 -mcpu=cortex-m3 开关,看起来 GPRbuild 也以某种方式将此开关传递给链接器。这是我的 .gpr 文件:

project Avocado_Test is

   for Source_Dirs use ("source");
   for Object_Dir  use "build";
   for Main use ("source/run_avocado_test.adb");

   for Target use "arm-eabi";
   for Runtime ("Ada") use "ravenscar-sfp-sam3x8e";

   package Builder is
      for Executable_Suffix use ".elf";
      for Switches ("Ada") use ("-j0");
   end Builder;

   package Compiler is
      for Driver ("Ada") use "arm-eabi-gcc";
      for Switches ("Ada") use (
        "-mthumb",
        "-mcpu=cortex-m3",
        "-O2");
   end Compiler;

   package Binder is
      for Driver ("Ada") use "arm-eabi-gnatbind";
   end Binder;

   package Linker is
      for Driver use "arm-eabi-ld";
   end Linker;

end Avocado_Test;

为什么链接器要从编译器中切换?我该如何防止这种情况?

我根本不会在任何 GPR 包中使用 Driver。一旦 gprbuild 看到 for Target use "arm-eabi"; 它就知道要在每个工具前添加 arm-eabi-

没有理由避免将编译器开关传递给默认链接器驱动程序,即 gcc(在本例中为 arm-eabi-gcc),因为它知道将其中哪些传递给链接器。

你可能会从我的 cortex-gnat-rts project: runtime.xml (but note, details may differ from AdaCore’s runtimes), testbed.gpr 中发现这些有趣的东西。