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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8fec429719a29bf9 X-Google-Attributes: gid103376,public From: "Vincent P. Amiot" Subject: Re: Interface between ADA and C++ Date: 1996/05/24 Message-ID: <31A63D04.2774@thomsoft.com>#1/1 X-Deja-AN: 156624651 sender: news@thomsoft.com (USENET News Admin @flash) x-nntp-posting-host: alesia references: <31A2C469.41C6@essiris2.atlas.de> content-type: text/plain; charset=us-ascii organization: Thomson Software Products mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 3.0b4Gold (WinNT; I) Date: 1996-05-24T00:00:00+00:00 List-Id: 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 > > 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 | > +------------------------------------------------------------------------+