comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis LaCroix <dennis.lacroix@ti.com>
Subject: Ada/C++ linkange on SGI.
Date: 1996/10/08
Date: 1996-10-08T00:00:00+00:00	[thread overview]
Message-ID: <325A9700.384A@ti.com> (raw)


Does anyone have any experience with trying to call C++ class functions
from an Ada program?  I'm trying to create instances of a class in
C++, and call functions for particular instances from Ada.

I'm on an SGI with the following configuration:

Operating system: IRIX 6.2
C++ compiler    : MIPSpro C++ 6.2
Ada compiler    : Verdix VADS 6.2

I've managed to call standalone C++ functions from Ada.  Here is an
example of what I did:

First compile the C++ code and make it into a shared object file using
a command similar to the following:

CC -o cpp_routine.so -elf -shared cpp_routine.c++

Then create an Ada wrapper routine to be used throughout the Ada code:

--------
with System;
package Wrapper is

   procedure CPP_Routine;
   pragma Interface (C, CPP_Routine);
   pragma Interface_Name (CPP_Routine, "cpp_routine__Fv");

end Wrapper
--------

I used the "nm" command on the cpp_routine.so file to get the link name
used in the Interface_Name pragma.  I'm currently experimenting with
the 'extern "C"' construct in C++ to avoid having to appending the
suffix (the format of the suffix is documented in "C++ Language System
Overview - Chapter 9, Type-Safe Linkage for C++" - type "insight" on
the SGI to bring up this online documentation). 

I used an Ada link command similar to the following to link the
executable:

a.ld -L lib -o test_c++.exe ada_main -old_ld cpp_routine.so -rpath 
{directory with cpp_routine.so in it}

This technique also works with functions that have parameters.

Here's what I CAN'T get to work:

I've got a C++ class with various public functions and variables.  I've
created a shared object file (.so) for the class.  If I use the "nm" 
command on this file then I see link names for each of the class
functions. 

I've also got a C++ file that declares an instance of this class.  I've
created another shared object file containing the instance.  When I do
an "nm" on this file then all I see is a link name for the object
instance.

I can use the Ada wrapper technique given above to call the functions
in the CLASS object file (but only for simple functions like
'cout << "yup, worked" << endl', parameter passing and accessing class
data doesn't work.)

If, for example, I had two instances of the class I want to be able
to call INSTANCE1.class_function() and INSTANCE2.class_function() from
Ada.  Does anyone have any insight about how I might do this?

Thanks.




             reply	other threads:[~1996-10-08  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-08  0:00 Dennis LaCroix [this message]
1996-10-09  0:00 ` Ada/C++ linkange on SGI Kenneth Almquist
replies disabled

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