Next: , Previous: Using External Variables, Up: Examples of Project Files

11.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 compile this unit under control of a project file, the dependent project must import the projects containing the needed source files. This effect is obtained using syntax similar to an Ada with clause, but where withed entities are strings that denote 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. Suppose that the source files for GUI_Proj are and gui.adb, and that the source files for Comm_Proj are and comm.adb, where each set of files is located in its respective project file directory. Schematically:


We want to develop an application in directory /app that with 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, the directory name of an imported object can be omitted if either

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

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

Importing other projects can create ambiguities. For example, the same unit might be present in different imported projects, or it might be present in both the importing project and in 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.