2. Introduction to GNAT for Cross Platforms

Cross platforms are where the compiler toolchain produces binaries for a target that is not the same as the host. For GNAT, there are two types of cross platforms: cross targets and bareboard targets. Cross targets are where the target has an embedded operating system like VxWorks or Linux. Bareboard targets are those where the run-times do not depend on operating system services and can run directly on top of the processor. GNAT distinguishes the two kinds of targets because there are differences between the two in workflow and customizability of the run-time libraries.

The general workflow for GNAT for cross platforms is similar to GNAT for native platforms, primarily through the support provided through the GNAT project facility. To begin using GNAT with cross platforms, it’s important to understand the naming of the tools provided, and how to specify the target and run-time library in GNAT projects.

2.1. Toolchain for Cross Platforms

Most of the tools described in the GNAT User’s Guide for Native Platforms are available for use on cross platforms. The major difference is that the name of the cross tools includes the name of the target. For instance, the cross gcc tool is invoked as <target>-gcc, where <target> stands for the name of the cross target. Thus, in an environment configured for the target arm-elf, the gcc command is arm-elf-gcc. This convention allows the installation of a native and one or several cross-development environments on the same machine. An exception to this is the GPRbuild tools, which are not prefixed by target, as they are target-independent tools.

The rest of this manual generally refers to the tools with their simple native names (e.g., gcc) when describing their generic functionality, and with their full cross names (e.g., <target>-gcc) when describing their invocation.

Note: gnatmake is not provided for bare-metal platforms, and is deprecated on cross platforms and may not be available in the future. GPRbuild should be used instead.

2.2. Specifying the Target

When using the GNAT Project facility, there are two ways to specify the target to use: via the GPR project file or a command-line switch. The recommended approach is to specify the target within a project file using the Target attribute:

project Demo is
   ...
   for Target use "arm-eabi";
   ...
end Demo;

On the command line, you can use the –target switch to specify the run-time library. For example, the following shows an invocation of gprbuild for an ARM target:

$ gprbuild --target=arm-eabi -P demo_leds.gpr

The names for the targets vary with the architecture of the intended platform, and are documented in their specific sections. Note that the names are reflected in the names of the cross-development versions of the AdaCore tools.

2.3. Specifying the Run-Time Library

The cross and bareboard compilers provide a set of run-time libraries offering subsets of the Ada language for different use cases. These run-time libraries differ by target and are documented in the corresponding target-specific sections They may be selected via an attribute in the project’s GPR project file or as a command-line switch to GPRbuild.

The contents of a run-time library is located in a folder with that library name (see Customized Bareboard Run-Time Libraries for those files and directories). If the library is installed in the default compiler toolchain location, the library can be specified as a simple name. Otherwise, you must specify an absolute or relative path to the named run-time library directory.

The recommended approach is to specify the run-time library through the project file using the Runtime attribute:

project Demo is
   ...
   for Runtime ("Ada") use "embedded-tms570";
   ...
end Demo;

Note the inclusion of the language name as the index to the attribute.

On the command line, you can use the –RTS= switch to specify the run-time library name.

2.4. GNAT C/C++ for Cross Platforms

2.4.1. Supported C++ Version

Unless explicitly documented otherwise for a given platform, the most recent version of C++ supported by GNAT is C++-17.

2.4.2. Mixed-Language Programming using GNAT Exclusively

For mixed Ada and C/C++ projects built using both GNAT (Ada) and GNAT C++, the GNAT (Ada) and GNAT C++ toolchains must have matching versions, and must both be installed at the same location. In that configuration, both GNATbench and GPRbuild may be used to build mixed Ada and C/C++ applications.

When compiling a mixed-language project, GNATBench or GPRbuild will insert the relevant includes and switches automatically. For GPRbuild, the first C/C++ compiler on the path will be selected; consequently, to use GNAT C and/or GNAT C++ to compile C/C++ code, ensure that this compiler appears on the path before the VxWorks compilers, or select it explicitly using GPRconfig. The compiler selection happens automatically when using GNATBench.