In this tutorial we will create and build a fully executable (simple) project. We have chosen to create a project for an embedded computer because it highlights some of the additional capabilities provided by GNATbench; the process is almost exactly the same for creating executables for native execution on the host computer.
Building a project for Ada development is easy with GNATbench. The wizard will create and configure the project for us, and invoking the builder is simply a matter of selecting a command.
The first step is to invoke the wizard. Using the Ada toolbar addition, click on the arrow next to the new-project icon and select "Basic Ada Project", as shown in the following figure:
The first page of the new-project wizard (shown in the next figure) will appear. Enter the name of the new project. We have named this one "ppc_elf_demo". We have the option of locating the new project in the default workspace or elsewhere in the file system. We'll take the default. Press Next.
In the next page we enter the name of the Ada main subprogram -- not the file name -- and have the wizard generate the file containing that unit. We arbitrarily name the unit "hello".
On that same page we then choose to use the PowerPC Elf compiler by selecting it from the list of preconfigured builders. This selection will enable the Finish button.
Press Finish. The new project will be created and you will see it in the Navigator, like so:
Note the presence of the files named "Makefile" and "ppc_elf_demo.gpr". These are the makefile and GNAT project file, respectively. These files may be edited but they must not be deleted.
Also note the file containing the main subprogram. This file will have the name we specified, "hello.adb", and will contain a procedure with that unit name:
In a real application we would alter the content of the main subprogram. It is a buildable subprogram, though, without any changes, so for the purpose of this tutorial we can leave it as it is.
We need a linker script to link the executable because this is a bare-board application. Hence we must tell the linker how to find this script so we modify the GNAT project created by the wizard.
The orignal project file looks like this:
We add the Linker package for the sake of the script:
We also have to insert this script into the workspace project. We have a stored copy on disk so an easy way to get it into the project is to use the Import... wizard and get the script from the file system.
Select "File System" under the "General" category and press Next.
After browsing to the location and selecting the file, simply press Finish and the file will be imported into the project.
We need to compile an assembly language source file and place it in the object directory before we can successfully link the application. This assembly source file contains startup code necessary for the application to run on the bare machine.
Like the script, this source file is stored on disk so we import it the same way we imported the linker script. Importing this file is identical in method to the other use of Import... for the script, so we omit showing it here.
We will call the command "setup" since we only need to compile the assembly source file once and place the resulting object file into the objects' directory. In practice we would have the Makefile automatically invoke this command when necessary, but we will do it manually for the sake of this tutorial.
Therefore, we modify "Makefile" to add a "setup" command. This command will be added to the bottom of the Makefile:
Note the comment above the target name. This comment will appear in the dialog box to serve as a reminder of what the new command does.
We must compile that assembly file because this is the first time we have built the project. We created the user-defined "setup" command for that purpose so we open the Navigator's contextual menu and choose "Build Target In Project..." to get the list of commands available.
The list of all predefined and user-defined commands appears:
Select the name "setup" among the listed build target names and press Build. Command execution will be displayed in the console.
If we then expand the "objs" dir in the Navigator we see the resulting object file:
Now that the setup has completed we are ready to do the full build. In the Eclipse menubar, open the Project menu and select "Build Project".
The build will then proceed and we can watch it in the build console. In this case we see in the console that the build failed due to an unresolved symbol named "_gnat_stack_check".
This particular run-time library does not include stack checking routines. Recall that the project file from the wizard included this option, among others:
We must edit the project file to remove the "-fstack-check" switch from the package Compiler. After you remove the switch be sure to save the changes to the project file.
We can then rebuild the project. Open the contextual menu in the Navigator and select "Rebuild Current Project":
A successful rebuild will look like the following:
That's it! You have created and built a project for an embedded computer using GNATbench for Eclipse.