Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same Base Package in Multiple Linked GPRBuild Projects

Tags:

ada

gnat

gprbuild

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?

like image 937
D. Ataro Avatar asked Nov 02 '18 18:11

D. Ataro


Video Answer


1 Answers

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
like image 102
Simon Wright Avatar answered Oct 19 '22 09:10

Simon Wright