如何与.gpr项目文件和gprbuild交叉编译?

时间:2019-08-02 09:59:40

标签: compilation cross-compiling ada gnat gprbuild

我正在尝试从Linux( Fedora 29 )交叉编译一个以Windows为目标的Ada程序。我对编译一无所知,Gnat project manager doc无法帮助我。 我更喜欢在项目文件中使用开关,并保持命令尽可能简单。我该怎么办?

我尝试了gprbuild -P logfilter.gpr --target=Windows导致

Error: no compiler found for language 'c', target = Windows, default runtime
Error: no compiler found for language 'ada', target = Windows, default runtime
logfilter.gpr:3:09: warning: no compiler specified for language "Ada", ignoring all its sources
logfilter.gpr:7:19: "log_filter_main.adb" is not a source of project "logfilter"
gprbuild: problems with main sources

这是我的gprconfig

prconfig has found the following compilers on your PATH.
  Only those matching the target and the selected compilers are displayed.
   1. GNAT for Ada in /usr/bin/ version 8.3 (default runtime)
   2. GCC-ASM for Asm in /usr/bin/ version 8.3.1
   3. GCC-ASM for Asm2 in /usr/bin/ version 8.3.1
   4. GCC-ASM for Asm_Cpp in /usr/bin/ version 8.3.1
   5. LLVM for C in /usr/bin/ version 7.0.1
   6. GCC for C in /usr/bin/ version 8.3.1
   7. G++ for C++ in /usr/bin/ version 8.3.1

和我的gprconfig --show-targets

List of targets supported by a compiler:
x86_64-redhat-linux
x86_64-unknown-linux-gnu

这是我的file.gpr

with "../../lib/gnat/gtkada";

project LogFilter is
    for Source_Dirs use ("src");
    for Object_Dir  use "obj";
    for Exec_Dir    use "exec";
    for Main use ("log_filter_main.adb");

   package Builder is
      for Executable ("main.adb") use "Logs_Filter";
   end Builder;

   package Compiler is
      for Switches ("ada") use ("-gnat2012");
   end Compiler;

end Logfilter;

2 个答案:

答案 0 :(得分:3)

一旦我使用Fedora 24做到了这一点,但这需要构建一个交叉编译器。我还有docker image

patches for fedora packages

我在fedora上提出了在交叉编译器的Windows中包含ada的请求,但他们将其关闭。但是,我找不到错误编号。

如果您对该版本的新版本或使用说明感兴趣,请告诉我。

更新:我已经为FC29重建了十字架。您可以这样尝试:

dnf copr enable reznik/ada
dnf install mingw64-gcc-gnat
dnf install gprbuild

sed -i -e 's/-pc-mingw/-w64-mingw/g' /usr/share/gprconfig/*

cat > hello.adb << EOF
with Ada.Text_IO;
procedure Hello is
begin
   Ada.Text_IO.Put_Line ("Hello");
end Hello;
EOF

cat > hello.gpr << EOF
project Hello is
   for Main use ("hello.adb");
end Hello;
EOF
gprbuild --target=x86_64-w64-mingw32 -P hello.gpr
file hello.exe

hello.exe: PE32+ executable (console) x86-64, for MS Windows

PS:link to copr

答案 1 :(得分:2)

正如其他人指出的那样,您遇到的问题是因为您没有使用cross compiler。 只是为了澄清有关gprbuild的内容,这可能会使它更清楚:gprbuild只是系统上gccgnat版本的前端。本质上,它只是make的特定于Ada的类似物。它处理项目配置文件并确定要构建项目的哪些部分。从gprconfig输出看来,您正在使用从Fedora存储库获得的FSF GNAT。 gprconfig --show-targets仅向您显示$PATH中发现的本机Linux编译器中的targets

要解决您的问题,您需要找到一个针对Windows的Ada编译器,说起来容易做起来难。在针对Linux构建GCC交叉编译器时,我遇到了各种各样的问题。如果您愿意的话,AdaCore提供一个相当不错的本机Windows编译器。希望我能提供更多帮助,但是我想您在遇到这种情况的交叉编译器时会遇到很多麻烦。在GCC中对Ada的跨编译器支持充其量似乎是偶然的。