Next: , Previous: , Up: Compiling Examples   [Contents][Index]

6.2 Set compiler options

This example illustrates using an Emacs Ada mode project file to set a compiler option.

If you have files from Example_1 open in Emacs, you should close them so you don’t get confused. Use menu ‘File | Close (current buffer)’.

In directory Example_2, create these files:


with Ada.Text_IO;
procedure Hello
is begin
   Put_Line("Hello from hello.adb");
end Hello;

This is the same as hello.adb from Example_1. It has two errors; missing “use Ada.Text_IO;”, and no space between Put_Line and its argument list.



This tells the GNAT compiler to check for token spacing; in particular, there must be a space preceding a parenthesis.

In buffer hello.adb, invoke ‘Ada | Project | Load...’, and select Example_2/hello.adp.

Then, again in buffer hello.adb, invoke ‘Ada | Set main and Build’. You should get a *compilation* buffer containing something like (the directory paths will be different):

cd c:/Examples/Example_2/
gnatmake -o hello hello -g -cargs -gnatyt  -bargs  -largs
gcc -c -g -gnatyt hello.adb
hello.adb:4:04: "Put_Line" is not visible
hello.adb:4:04: non-visible declaration at
hello.adb:4:04: non-visible declaration at
hello.adb:4:12: (style) space required
gnatmake: "hello.adb" compilation error

Compare this to the compiler output in No project files; the gnatmake option -cargs -gnatq -gnatQ has been replaced by -cargs -gnaty, and an additional error is reported in hello.adb on line 4. This shows that hello.adp is being used to set the compiler options.

Fixing the error, linking and running the code proceed as in No project files.

Next: , Previous: , Up: Compiling Examples   [Contents][Index]