comp.lang.ada
 help / color / mirror / Atom feed
From: "Vincent P. Amiot" <vamiot@thomsoft.com>
Subject: Re: Interface between ADA and C++
Date: 1996/05/24
Date: 1996-05-24T00:00:00+00:00	[thread overview]
Message-ID: <31A63D04.2774@thomsoft.com> (raw)
In-Reply-To: 31A2C469.41C6@essiris2.atlas.de


Norbert Roeben wrote:
> 
> Hi,
> 
> I'm trying to find a way to interface ADA with C++.
> I'm using GNAT 3.03 with gcc 2.7.2 with g++ library 2.7.1.
> 
> I try to call an C++ function from Ada. The linker always searches for
> C - function, not for a C++ - function.
> 
> Does anybody has a solution for this ?
> 
> Here an extract from my sources and the way I compiled them :
> 
> ADA Sources :
> 
> file hellointerface.ads :
> 
>         package HelloInterface is
> 
>            procedure CppHello          ( Text    : String  );
> 
>           private
> 
>           -- Interface to a C++ - function
>           pragma Import       ( Cpp,CppHello,"CppHello");
> 
>         end HelloInterface;
> 
> file hello.adb :
> 
>         with text_io;
>         with HelloInterface;
> 
>         procedure Hello is
> 
>         begin
> 
>            HelloInterface.CppHello ("And it works with C++");
> 
>         end;
> 
> C++ Source :
> 
> file cppHello.cc :
> 
>         #include <iostream.h>
> 
>         void CppHello ( char *String ) {
> 
>           cout << String << endl;
> 
>         }
> 
> The way how I compiled them:
> 
> gcc -g -c hello.adb
> gcc -g -c hellointerface.ads
> g++ -g -c cppHello.c
> gnatbl hello.ali -o hello cppHello.o cHello.o -lg++ -lstdc++
> 
> The Error Message I got :
> 
>         No code generated for file hellointerface.ads (package spec)
>         No code generated for file except.ads (package spec)
>         collect2: ld returned 1 exit status
>         /usr/bin/../lib/ld:
>         Unresolved:
>         CppHello
> 

-- Your C++ external name must be mangled: the profile of your C++ routine
-- is combined with its human readable original name to give a funky name:

on HP with my (GNU?) C++ I get


$ nm -x cpphello.o


Symbols from cpphello.o:

Name                    Value   Scope  Type    Subspace

$global$            |          |undef |data   |
CppHello__FPc       |0x00000000|extern|entry  |$CODE$
__ls__7ostreamPCc   |          |undef |code   |
__ls__7ostreamPFR7ostream_R7ostream|          |undef |code   |
cout                |          |undef |data   |
endl__FR7ostream    |          |undef |code   |                      

 
CppHello__FPc is your 'mangled/funky' name, mangling you have guessed
it is used to enforce confomance rules (via ld) in C++.


some systems provide unmangle/demangle tools to translate the name.

Note that even if you get the name right:

   - mangling schemes may vary from C++ compiler to C++ compiler and 
     from version to version.

   - fishing out the proper name is likely not to be enough, the C++
     runtime must still coexist peacefully with the Ada RTS.

     The trick may be to offer the C++ services in DLLS/Shared Libs
     (such beasts tend to have better defined behaviors)

Have Fun

Vincent

> --
> +-----------------+----------------------+-------------------------------+
> | Norbert Roeben  | DEPARTMENT :  ETS 52 |  PHONE : (49) 421-4573695     |
> +-----------------+----------------------+-------------------------------+
> | EMAIL  : roeben@essiris2.atlas.de                                      |
> +------------------------------------------------------------------------+
> | STN ATLAS Elektronik            Brueggeweg 54            28305 Bremen  |
> +------------------------------------------------------------------------+




      parent reply	other threads:[~1996-05-24  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-22  0:00 Interface between ADA and C++ Norbert Roeben
1996-05-23  0:00 ` Kevin F. Quinn
1996-05-23  0:00   ` Mike Young
1996-05-24  0:00     ` Darren C Davenport
1996-05-29  0:00       ` Ken Slater
1996-05-29  0:00         ` Ding-yuan Sheu
1996-05-24  0:00 ` Vincent P. Amiot [this message]
replies disabled

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