Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ada: Gnat Gprbuild Add a binary library with no .adb to a project

Tags:

ada

gprbuild

I have built a static library in Ada with Gnatstudio/Gprbuild. Now, I would like to use it in a executable project, but I only want to give .ads files and binary .a. No .adb.

My executable project gpr file looks like this:

with "../Libraries/my_lib.gpr";

project Test is

   for Source_Dirs use ("src");
   for Object_Dir use "obj";
   for Main use ("test.adb");

   package Linker is
      for Default_Switches ("ada") use ("-L../Libraries/lib", "-lmy_lib");
   end Linker;

end Test;

and library gpr file looks like this:

library project my_lib is

   for Languages use ("Ada");
   for Library_Name use "my_lib";
   for Source_Dirs use ("src");
   for Object_Dir use "obj";
   for Library_Dir use "lib";
   for Library_Kind use "static";

end my_lib;

When I compile project with library containing ads and adb files in library src dir, everything works fine and compiles like a charm.

But when I remove adb files from library src directory, gpbuild complains it cannot compile ads files.

Compile
   [Ada]          my_lib.ads
cannot generate code for file my_lib.ads (package spec)

And, yes, it's right. It cannot compile standalone ads file.

If I add for Excluded_Source_Files use ("my_lib.ads"); in my_lib.gpr, then compiler complains it cannot find my_lib.ads:

Compile
   [Ada]          test.adb
test.adb:2:06: error: file "my_lib.ads" not found

So, here is my question: How can I give a project a static library with only .ads and .a file BUT prevents compiler to try compiling standalone ads file as they are necessary for dependency but do not need to be compiled.

It so easy to do in C/C++, I'm a bit surprized how hard it is to do in Ada.

like image 920
dimercur Avatar asked Oct 13 '25 01:10

dimercur


1 Answers

OK, I've got it!

In library gpr file, you need to remove Object_Dir line and set Externally_Built switch:

So, first, compile your library normally. Then modify (or create another) library gpr file. My library gpr file looks like this now:

   library project my_lib is

   for Languages use ("Ada");
   for Library_Name use "my_lib";
   for Source_Dirs use ("src");
   -- for Object_Dir use "obj";
   for Library_Dir use "lib";
   for Library_Kind use "static";
   for Externally_Built use "true";

end my_lib;

Then, you can remove adb from library src directory and recompile main project: everything compile fine.

In fact, it was written in grpbuild documentation, here

like image 194
dimercur Avatar answered Oct 16 '25 05:10

dimercur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!