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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1b85793c9263ca04 X-Google-Attributes: gid103376,public From: "Stanley R. Allen" Subject: Re: C++ to Ada Link Problems Date: 1998/02/27 Message-ID: <34F71D58.2781@hso.link.com>#1/1 X-Deja-AN: 329259450 Content-Transfer-Encoding: 7bit References: <9802271359.AA07254@nile.gnat.com> <34F6CC30.D8B74ACB@mps.lmtas.lmco.com> Content-Type: text/plain; charset=us-ascii Organization: NASA, Kennedy Space Center Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-02-27T00:00:00+00:00 List-Id: James Huckaby wrote: > > > Simply put, is it at all possible with the resources I have now > (Sun Ada 2.1 and Sun C++ 3.0, upgrading soon to Sun Ada 3.0, and > Sun C++ 4.0) to link Ada and C++? "Linking C++ and Ada" is an umbrella topic. You might mean by this that you need to "interface" Ada and C++. If so, you may need to set up some C code which calls the C++ code, and interface the Ada to this using pragma Interface. But by the wording of your question, I suppose that you have alreasy worked out those issues and are trying now to build an executable. The main issue is C++ constructor/ deconstructor ("Xtor") operations for statically-declared object instances: how do they get called? In Ada, global variable initialization is defined in the language as part of the elaboration process. In C++, it is the job of external tools. A common way of creating the contructor/destructor caller is to "munch" the object code produced by the C++ compiler (using a munching tool), which will produce a C file that calls the Xtors. Compiling this C file and linking the new object module with the C++ code will ensure that the C++ static objects are constructed properly. To link with Ada, ensure that the object file created from the C program is included as one of the inputs to the linker building the Ada main. (Since you are talking about Ada 83, I assume that the main program is in Ada.) My understanding is that munching is the approach used by the GNU C++ implementation. Other C++ compilers don't require a separate munching phase, but expect that the linker will include calls to the proper contructor/destructors. If the Ada binding program (I think that would be a.ld for SunAda) is used to create the Unix "ld" command, then the stuff C++ needs will not be included. I'm not sure how it works on the Sun; on the SGI with Delta C++ you can specify that the C++ compiler itself ("CC") be used as the linker. This will include the necessary code to call the Xtor operations for static C++ objects. Disclaimer: I have only done the above with GNAT, but I believe the same principles apply when linking code produced by other Ada compilers. -- Stanley Allen mailto:s_allen@hso.link.com