comp.lang.ada
 help / color / mirror / Atom feed
From: julian_robbins@bigfoot.com (Julian Robbins)
Subject: Calling Ada from C++ (MS Visual C++)
Date: 5 Apr 2002 00:30:59 -0800
Date: 2002-04-05T08:30:59+00:00	[thread overview]
Message-ID: <3ab585c8.0204050030.3d94e692@posting.google.com> (raw)

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



             reply	other threads:[~2002-04-05  8:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-05  8:30 Julian Robbins [this message]
2002-04-05 18:18 ` Calling Ada from C++ (MS Visual C++) Stephen Leake
2002-04-11  8:51   ` Julian Robbins
2002-04-11 17:15     ` Stephen Leake
2002-04-16 12:27       ` Karel Miklav
2002-04-16 14:07         ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2002-04-05 10:26 Caldwell Ian
replies disabled

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