2
votes

I'm trying to cross-compile from Linux (Fedora 29) an Ada program with Windows as target. I have no knowledge about compilation and the Gnat project manager doc couldn't help the noob I am. I would prefer to use switches inside the project file and keep the command the simplest possible. What should I do?

I tried gprbuild -P logfilter.gpr --target=Windows which leads to

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

Here is my 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

and my gprconfig --show-targets:

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

here is my 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
It doesn't seem like you have a cross-compiler installed.egilhh
Isn't grpbuild able to cross compile by itself with the good parameters?Lyaaaaaaaaaaaaaaa
well, no. It needs to know about the target compiler, and your gprconfig --show-targets only lists linux targets...egilhh
I noticed it only list linux targets. I will search a cross compiler.Lyaaaaaaaaaaaaaaa
In general, you need to follow these instructions to build a gnat cross compiler.TamaMcGlinn

2 Answers

5
votes

Once I did this with Fedora 24. But this required to build a cross compiler. I still have a docker image

and patches for fedora packages

I filled a request on fedora to include ada in windows in cross compiler, but they closed it. I'm unable to find the bug number, however.

Tell me if you are interested in fresh version of this or instructions how to use.

Update: I've rebuilt cross for FC29. You can try it this way:

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

4
votes

As others have pointed out, the issue you're encountering is because you're not using a cross compiler. Just to clarify something about gprbuild that might make this clearer: gprbuild is just a front-end for the versions of gcc and gnat on your system. Essentially it's just an Ada-specific analogue of make. It processes the project configuration file and works out what parts of the project to be built. From the gprconfig output it looks like you're using the FSF GNAT obtained from the Fedora repos. gprconfig --show-targets is only showing you the targets of the native Linux compilers that it's found in your $PATH.

To solve your problem you'll need to find an Ada compiler targeting Windows. AdaCore provide a pretty decent native Windows compiler if that's an option for you.