Same Base Package in Multiple Linked GPRBuild Projects
Asked Answered
D

1

6

With GPRBuild, I have created a library project called Lib. All packages in Lib reside within the package Base, which I use as a base package: to have a base package Base. For instance, if I were to create package Apple in any library or application I make, it would be written out as package Base.Apple.

The problem with this, using GPRBuild. In order to put things under the Base package, it needs to exist. In the GPRBuild library project Lib, I therefore have a file base.ads denoting the existance of package Base. Then in the project where I'm using the library Lib, let's refer to it as Proj, I also put all my packages under the Base package (the packages inside Proj). In order to do so, we need to create a base.ads file for Proj too with the package definition for just that, Base.

Let's have a look at the gpr project file:

with "lib.gpr";

project Proj is
   -- ...
end Proj;

Through this arises the problem; we suddenly have two files, both called base.ads, both defining the Base package, one in each project: the library project Lib, and the project Proj using the library Lib. As we have two packages (and their files) named the same thing, we get this error, which at all is not surprising, at compile time:

unit "base" cannot belong to several projects

The question is: is there a way to have the same base package in multiple projects? Projects that are then linked together through an import (with). If it should prove to be possible, how can it be achieved?

Durban answered 2/11, 2018 at 18:45 Comment(0)
A
6

You need to put the Base package in a project of its own. The following is a minimal demo.

In base/,

project Base is
end Base;

package Base is
end Base;

In lib/,

with "../base/base.gpr";
project Lib is
end Lib;

package Base.Lib is
end Base.Lib;

In proj/,

with "../lib/lib.gpr";
project Proj is
end Proj;

with Base.Lib;
package Base.Proj is
end Base.Proj;

Then,

$ cd proj/
$ gprbuild
using project file proj.gpr
Compile
   [Ada]          base.ads
   [Ada]          base-lib.ads
   [Ada]          base-proj.ads
Aloha answered 2/11, 2018 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.