comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Re: How to supply O/S linker arguments with gprbuild?
Date: Mon, 22 Jun 2020 10:52:20 -0700 (PDT)	[thread overview]
Message-ID: <98843f83-9907-4bd4-9600-4bc67e41f883o@googlegroups.com> (raw)
In-Reply-To: <rcqmr4$1rc9$1@gioia.aioe.org>

On Monday, 22 June 2020 12:39:05 UTC-4, Dmitry A. Kazakov  wrote:
> On 22/06/2020 17:51, Warren wrote:
> > I have a GNAT project that has these pragma statements embedded to get the sucker to link. However, the directory is only valid for an instance on my Mac, so I need a better solution to replace:
> > 
> >     pragma Linker_Options("-L/usr/local/Cellar/readline/8.0.4/lib");
> >     pragma Linker_Options("-lreadline");
> > 
> > I've tried to find the solution in the gnat documents but they seem to fall short of what I need to do (could not find an example nor direction in this -- perhaps I missed it).
> > 
> > My project file looks something like this:
> > 
> > project MyProject is
> >      for Languages use ("ada", "c");
> >      for Source_Dirs use ("src");
> >      for Object_Dir use "obj";
> >      for Main use ("main.adb");
> > end MyProject;
> > 
> > I've tried a variety of gpr things, but unsuccessfully.
> 
> There are many ways to do this.
> 
> Here I give one rarely used but most flexible and consistent with the 
> idea of projects.
> 
> If you have an alien library like readline, you can pack it in a 
> separate library project like this:
> 
> project Readline is
>     for Externally_Built use "true"; -- Do not build it
>     for Source_Files use ();         -- No sources
>     for Library_Dir use "/usr/local/Cellar/readline/8.0.4/lib";
>     for Library_Name use "readline"; -- OS naming conventions applied
>     for Library_Kind use "dynamic";  -- Or static,
> end Readline;                       -- depending on what you have
> 
> In your project or projects you would simply do
> 
> with "readline.gpr";
> 
> and that is all.
> 
> Adjust the above using a scenario variable to select the target OS, e.g.
> 
>     type OS_Type is
>          (  "Windows", "Windows_NT",
>             "Linux",
>             "UNIX",
>             "OSX",
>             "FreeBSD",
>             ...
>          );
>     Target_OS : OS_Type := external ("Target_OS", "MS-DOS");
> 
>     case Target_OS is
>        when "ms-dos" =>
>           for Library_Dir use "...";
>        when "osx" =>
>           for Library_Dir use "...";
>           ...

The above might be useful for some projects, but I didn't want to define a package for each and every library I link with. I have a simple Makefile that drives this project, and I simply wanted a central place to configure the pathnames. 

So I managed to get this to work:

project MyProject is   
  for Languages use ("ada", "c");
  for Source_Dirs use ("src");
  for Object_Dir use "obj";
  for Main use ("main.adb");
  package Linker is
    for Required_Switches use ( "-L/usr/local/Cellar/readline/8.0.4/lib", "-lreadline" );
  end Linker;
end MyProject;   

In the final version of the .gpr file, I'll put some sentinel text like <readline_dir> and substitute it as required using sed from the Makefile.  Currently there is only one path I have to deal with but it might grow to several. I didn't want to define a package for each and every library referenced.

I find it amazing that there isn't a single instance of an example like this that I could goggle. The gprbuild doc seems to expend a great deal explaining every other use case, including building of library packages. All I wanted to do was to link an executable. That said, it is possible that my failing eyesight may have overlooked it.

Thanks everyone,
Warren

  reply	other threads:[~2020-06-22 17:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22 15:51 How to supply O/S linker arguments with gprbuild? Warren
2020-06-22 16:14 ` Mark Lorenzen
2020-06-22 16:30 ` Dennis Lee Bieber
2020-06-22 16:39 ` Dmitry A. Kazakov
2020-06-22 17:52   ` Warren [this message]
2020-06-22 20:07     ` Dmitry A. Kazakov
2020-06-22 20:43       ` Simon Wright
2020-06-22 20:59         ` Warren
2020-06-22 21:52           ` Simon Wright
2020-06-22 21:16         ` Dmitry A. Kazakov
2020-06-22 21:27           ` Warren
2020-06-22 21:47           ` Simon Wright
2020-06-22 22:08             ` Jeffrey R. Carter
2020-06-23  9:23 ` Björn Lundin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox