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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9b1d37f5a56928f1,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-04-05 00:30:59 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: julian_robbins@bigfoot.com (Julian Robbins) Newsgroups: comp.lang.ada Subject: Calling Ada from C++ (MS Visual C++) Date: 5 Apr 2002 00:30:59 -0800 Organization: http://groups.google.com/ Message-ID: <3ab585c8.0204050030.3d94e692@posting.google.com> NNTP-Posting-Host: 193.123.204.66 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1017995459 31622 127.0.0.1 (5 Apr 2002 08:30:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 5 Apr 2002 08:30:59 GMT Xref: archiver1.google.com comp.lang.ada:22140 Date: 2002-04-05T08:30:59+00:00 List-Id: Hi All, I have a question regarding calling Ada from Microsoft Visual C++. I am currently in the situation where I can export a function from an Ada package and then compile this into my C++ application, following the standard approach of pragma Export. For example, I have the spec/code as follows: package MathUtil is function Square( Value : in Float) return Float ; pragma export (CPP, Square, "ada_square") ; end MathUtil; package body MathUtil is function Square( Value : in Float) return Float is begin return Value * Value ; end Square; end MathUtil ; I can use gcc command (GNAT 3.14) to compile this into a .o file, include this in my Visual C++ project and then simply call the "ada_square" function from anywhere in my C++ code. This works and produces an executable that does what it is supposed to. However, this is a very simplistic model. I have done much reading on the subject of interfacing Ada and C++ and I believe that the above approach would fall over as soon as I started to put any real code in the Ada section. Specifically I am talking about the Ada executive functions and "ellaboration". The C++ program is the 'main' program and so no Ada 'main' is yet being called. Could some please comment on whether my assertion is correct? If I only include the .o files, at some point it is going to fall over horribly? So, using GNAT I believe that I can include the 'adainit()' and 'adafinal()' in the binding stage using 'gnatbind -n mathutil.ali'. However, this seems to produce a .o file that I could then only use with gnatlink to link the C++ objects and Ada objects together. This I can not do - I need to use MS Visual Studio to link the final executable, including any relevant Ada objects. My big question, therefore, is : Is this possible? Can I use the GNAT tools to create the adainit() and adafinal() functions in such a way that I can then simply include the object files into my Visual Studio project? Thanks in advance for any help! Julian Robbins Software Engineer Logica UK