www.delorie.com/gnu/docs/gcc/gnat_ug_113.html   search  
Buy the book!

Untitled Document

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.2.3 Importing Other Projects

A compilation unit in a source file in one project may depend on compilation units in source files in other projects. To obtain this behavior, the dependent project must import the projects containing the needed source files. This effect is embodied in syntax similar to an Ada with clause, but the "with"ed entities are strings denoting project files.

As an example, suppose that the two projects GUI_Proj and Comm_Proj are defined in the project files `gui_proj.gpr' and `comm_proj.gpr' in directories `/gui' and `/comm', respectively. Assume that the source files for GUI_Proj are `gui.ads' and `gui.adb', and that the source files for Comm_Proj are `comm.ads' and `comm.adb', with each set of files located in its respective project file directory. Diagrammatically:



We want to develop an application in directory `/app' that "with"s the packages GUI and Comm, using the properties of the corresponding project files (e.g. the switch settings and object directory). Skeletal code for a main procedure might be something like the following:

with GUI, Comm;
procedure App_Main is
end App_Main;

Here is a project file, `app_proj.gpr', that achieves the desired effect:

with "/gui/gui_proj", "/comm/comm_proj";
project App_Proj is
   for Main use ("app_main");
end App_Proj;

Building an executable is achieved through the command:
gnatmake -P/app/app_proj
which will generate the app_main executable in the directory where `app_proj.gpr' resides.

If an imported project file uses the standard extension (gpr) then (as illustrated above) the with clause can omit the extension.

Our example specified an absolute path for each imported project file. Alternatively, you can omit the directory if either

Thus, if we define ADA_PROJECT_PATH to include `/gui' and `/comm', then our project file `app_proj.gpr' could be written as follows:

with "gui_proj", "comm_proj";
project App_Proj is
   for Main use ("app_main");
end App_Proj;

Importing other projects raises the possibility of ambiguities. For example, the same unit might be present in different imported projects, or it might be present in both the importing project and an imported project. Both of these conditions are errors. Note that in the current version of the Project Manager, it is illegal to have an ambiguous unit even if the unit is never referenced by the importing project. This restriction may be relaxed in a future release.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003