From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a45dbca8d12d7200 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-27 16:44:14 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Binding and linking non-withed packages into an executable Date: 27 Jan 2004 19:44:13 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: pip1-5.std.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1075250653 22631 192.74.137.185 (28 Jan 2004 00:44:13 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 28 Jan 2004 00:44:13 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:4961 Date: 2004-01-27T19:44:13-05:00 List-Id: "Marc A. Criley" writes: > (I vaguely recall this topic previously being discussed in some forum > somewhere but have been unable to locate it.) > > I want to be able to have a compiled package bound and linked in with an Ada > executable, despite there being no "with" of that package. The reason is > that there are "access procedure variables" in the main set of code, which > this peripheral package can set to its own procedures during the elaboration > of the package. This is bound to be compiler-specific, so I'm using GNAT > 3.15p on Linux. > > Here's a toy illustration: > > -- A package with a "callback variable" > package Back_Caller is > type Callback is access procedure; > Cb : Callback; > end Back_Caller; > > -- The main program that invokes that callback variable. > with Back_Caller; > procedure Cb_Main is > begin > Back_Caller.Cb.all; > end Cb_Main; > > -- The peripheral package that supplies the callback... > package CB_Provider is > procedure My_Callback; > end CB_Provider; > > -- ...that the callback variable is set to during pkg elaboration. > with Text_IO; use Text_IO; > with Back_Caller; > package body CB_Provider is > procedure My_Callback is > begin > Put_Line("Invoking callback"); > end My_Callback; > begin > Back_Caller.CB := My_Callback'access; > end CB_Provider; > > > Invoking gnatmake on Cb_Main compiles just the Back_Caller package and > Cb_Main procedures, as one would expect. How can I get the CB_Provider > package bound (so it'll be elaborated) and linked in? I think you have to say "with CB_Provider;" somewhere in your system. By the way, there seems to be no need to export My_Callback. You could declare the package spec as: package CB_Provider is pragma Elaborate_Body; end CB_Provider; > I've looked at the various gnatbind options, but they're more geared for "no > main" or "non-Ada main" situations. > > Obviously I can have a "configuration package" that with's the "peripheral" > packages and is withed by the main, I think that's what you need to do. >... but I'd like to make the inclusion of > such packages a build, rather than compile, issue. This way new callback > packages can be brought in or omitted as needed (the actual app is of course > more sophisticated than the above toy), so no actual software would have to > change. Why? Build scripts are software! - Bob