comp.lang.ada
 help / color / mirror / Atom feed
* Calling Ada from C++ (MS Visual C++)
@ 2002-04-05 10:26 Caldwell Ian
  0 siblings, 0 replies; 7+ messages in thread
From: Caldwell Ian @ 2002-04-05 10:26 UTC (permalink / raw)


You can use a DLL. Have a look at 'Microsoft Windows Topics' section in the gnat user guide.

Ian Caldwell
Q218 
QinetiQ Malvern 
+ 44 (0) 1684 89 4461


-- 
The Information contained in this E-Mail and any subsequent correspondence
is private and is intended solely for the intended recipient(s).
For those other than the recipient any disclosure, copying, distribution, 
or any action taken or omitted to be taken in reliance on such information is
prohibited and may be unlawful.



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Calling Ada from C++ (MS Visual C++)
@ 2002-04-05  8:30 Julian Robbins
  2002-04-05 18:18 ` Stephen Leake
  0 siblings, 1 reply; 7+ messages in thread
From: Julian Robbins @ 2002-04-05  8:30 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-04-16 14:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-05 10:26 Calling Ada from C++ (MS Visual C++) Caldwell Ian
  -- strict thread matches above, loose matches on Subject: below --
2002-04-05  8:30 Julian Robbins
2002-04-05 18:18 ` 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

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