ada-mode: Set source search path
6.3 Set source search path
==========================
In this example, we show how to deal with files in more than one
directory. We start with the same code as in No project files;
create those files (with the errors present)
Create the directory ‘Example_3’, containing:
‘hello_pkg.ads’:
package Hello_Pkg is
procedure Say_Hello;
end Hello_Pkg;
‘hello_pkg.adb’:
with Ada.Text_IO;
package Hello_Pkg is
procedure Say_Hello
is begin
Ada.Text_IO.Put_Line ("Hello from hello_pkg.adb");
end Say_Hello;
end Hello_Pkg;
These are the same files from example 1; ‘hello_pkg.adb’ has an error
on line 2.
In addition, create a directory ‘Example_3/Other’, containing these
files:
‘Other/hello_3.adb’:
with Hello_Pkg;
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello_3
is begin
Hello_Pkg.Say_Hello;
Put_Line ("From hello_3");
end Hello_3;
There are no errors in this file.
‘Other/other.adp’:
src_dir=..
comp_opt=-I..
Note that there must be no trailing spaces.
In buffer ‘hello_3.adb’, invoke ‘Ada | Project | Load...’, and select
‘Example_3/Other/other.adp’.
Then, again in ‘hello_3.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_3/Other/
gnatmake -o hello_3 hello_3 -g -cargs -I.. -bargs -largs
gcc -c -g -I.. hello_3.adb
gcc -c -I./ -g -I.. -I- C:\Examples\Example_3\hello_pkg.adb
hello_pkg.adb:2:08: keyword "body" expected here [see file name]
gnatmake: "C:\Examples\Example_3\hello_pkg.adb" compilation error
Compare the ‘-cargs’ option to the compiler output in Set
compiler options; this shows that ‘other.adp’ is being used to set the
compiler options.
Move to the error with ‘C-x `’. Ada mode searches the list of
directories given by ‘src_dir’ for the file mentioned in the compiler
error message.
Fixing the error, linking and running the code proceed as in No
project files.