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: Mike Young Subject: Re: Interface between ADA and C++ Date: 1996/05/23 Message-ID: <31A51616.3222EAAC@str.com>#1/1 X-Deja-AN: 156416847 references: <31A2C469.41C6@essiris2.atlas.de> <31A46A6E.4B2F@banana.demon.co.uk> content-type: text/plain; charset=us-ascii organization: Fen Software, Inc. mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 3.0b4 (X11; I; Linux 1.2.13 i586) Date: 1996-05-23T00:00:00+00:00 List-Id: Kevin F. Quinn wrote: > > Norbert Roeben wrote: > > > I try to call an C++ function from Ada. The linker always searches for > > C - function, not for a C++ - function. > > Your problem is that the C++ function name is mangled by the C++ compiler, > almost certainly. > > > Does anybody has a solution for this ? > > Try adding something along the lines of (un-tried) > > extern "C" { > void GlueCppHello ( char *String ) { > CppHello(String); > } > } > > to your C++ source set - the 'extern "C" {}' construct ensures that the code > in between is treated as normal "C" code, and as such the function name > GlueCppHello isn't mangled. Then call GlueCppHello from your Ada code. > > > Unresolved: > > CppHello ================ Many C and C++ compilers prepend a '_' to the name, thusly: _CppHello. Try that if you continue to have problems. > > BTW - the above is a direct result of the change in function name by the C++ > compiler. There are a number of good reasons for this, but this is not the > place to go into them. If you have complete documentation on the C++ compiler, > it may well tell you how to determine the actual linker symbol generated, in > which case you can use this directly instead of using the 'extern "C" ' stuff. ========== The simple answer is not at all obscure, and it wouldn't hurt to describe it here. The C++ compiler simply tags the function name with return type, class name, argument signatures, access privileges, and possibly other bits of identifying information. This allows the linker to find the correct one of possibly many overloads. Extern C functions, OTOH, cannot be overloaded; decorated names are not emitted for extern "C" functions. As for guessing and using the decorated name: this is generally not a good idea. It's a pain in the behind, for one, not portable, for two, and extern C takes care of all this, for three. Mike.