comp.lang.ada
 help / color / mirror / Atom feed
* Calling C++ from within ADA
@ 1994-11-03 12:53 CVANOVER
  1994-11-03 15:11 ` Norman H. Cohen
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: CVANOVER @ 1994-11-03 12:53 UTC (permalink / raw)


Is there a way to call a C++ procedure from within ADA? I can call a C 
procedure with 

package C_LIB is
        procedure clear_screen;
        procedure sleep_a_moment;
private
        pragma interface(c,clear_screen);
        pragma interface(c,sleep_a_moment);
end C_LIB;

However, when I compile the same C procedure in C++ I get the following error:
0706-317 ERROR: Unresolved or undefined symbols detected:
                 Symbols in error (followed by references) are
                 dumped to the load map.
                 The -bloadmap:<filename> option will create a load map.
.clear_screen

I've tried adding INTERFACE_INFORMATION but it doesn't seem to help.  

I am using IBM AIX on an RS6000.

Thank you
Chris Vanover
The University of Alabama
CVanover@bamanet.ua.edu




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

* Re: Calling C++ from within ADA
  1994-11-03 12:53 Calling C++ from within ADA CVANOVER
@ 1994-11-03 15:11 ` Norman H. Cohen
       [not found] ` <CypvDM.8q5@nntpa.cb.att.com>
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Norman H. Cohen @ 1994-11-03 15:11 UTC (permalink / raw)


In article <CVANOVER.1.0007E49E@bamanet.ua.edu>, CVANOVER@bamanet.ua.edu
writes: 

|> Is there a way to call a C++ procedure from within ADA? I can call a C
|> procedure with
|>
|> package C_LIB is
|>         procedure clear_screen;
|>         procedure sleep_a_moment;
|> private
|>         pragma interface(c,clear_screen);
|>         pragma interface(c,sleep_a_moment);
|> end C_LIB;
|>
|> However, when I compile the same C procedure in C++ I get the following error: 
|> 0706-317 ERROR: Unresolved or undefined symbols detected: 
|>                  Symbols in error (followed by references) are
|>                  dumped to the load map.
|>                  The -bloadmap:<filename> option will create a load map.
|> .clear_screen
|>
|> I've tried adding INTERFACE_INFORMATION but it doesn't seem to help.
|>
|> I am using IBM AIX on an RS6000.

The error message comes from the linker, ld, which is invoked by the
compiler when you compile with -b or -m (to construct an executable main
program).  I suspect that your C++ compiler is creating a "mangled"
external name for clear_screen, rather than the name .clear_screen
created by your C compiler.  Use the AIX nm command to see the external
symbols in the .o file produced by your C++ compiler, and, if you can
figure out which one is a mangled name for clear_screen, adjust your
Interface_Information pragma accordingly.

--
Norman H. Cohen    ncohen@watson.ibm.com



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

* Re: Calling C++ from within ADA
       [not found] ` <CypvDM.8q5@nntpa.cb.att.com>
@ 1994-11-04 17:31   ` Greg Harvey
  1994-11-04 17:46     ` Greg Harvey
  0 siblings, 1 reply; 7+ messages in thread
From: Greg Harvey @ 1994-11-04 17:31 UTC (permalink / raw)


ka@socrates.hr.att.com (Kenneth Almquist) writes:

>CVANOVER@bamanet.ua.edu wrote:
>> Is there a way to call a C++ procedure from within ADA?  I can call a C 
>> procedure with 
>>
>> package C_LIB is
>>         procedure clear_screen;
>>         procedure sleep_a_moment;
>> private
>>         pragma interface(c,clear_screen);
>>         pragma interface(c,sleep_a_moment);
>> end C_LIB;
>>
>> However, when I compile the same C procedure in C++ [things don't work].

>Change the interface pragmas to tell the Ada compiler that the
>procedures are C++ procedures rather than C procedures.  If you can't
>do this becuase your Ada compiler doesn't know about C++, add the
>following to your C++ code:

>extern "C" void clear_screen(void);
>extern "C" void sleep_a_moment(void);

>This will tell the C++ compiler to use C calling conventions for these
>procedures.
>					Kenneth Almquist

Isn't this where the people who like to complain about object-based languages
with no static binding start showing up?

;)

Greg Harvey (harvey@blkbox.com)



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

* Re: Calling C++ from within ADA
  1994-11-04 17:31   ` Greg Harvey
@ 1994-11-04 17:46     ` Greg Harvey
  0 siblings, 0 replies; 7+ messages in thread
From: Greg Harvey @ 1994-11-04 17:46 UTC (permalink / raw)


harvey@blkbox.COM (Greg Harvey) writes:

>Isn't this where the people who like to complain about object-based languages
>with no static binding start showing up?

<sigh>  I meant no dynamic binding...which was a lot funnier.

>;)

>Greg Harvey (harvey@blkbox.com)



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

* Re: Calling C++ from within ADA
  1994-11-03 12:53 Calling C++ from within ADA CVANOVER
  1994-11-03 15:11 ` Norman H. Cohen
       [not found] ` <CypvDM.8q5@nntpa.cb.att.com>
@ 1994-11-07  2:52 ` Oliver E. Cole
  1994-11-08 15:22 ` Eric Beser
  1994-11-08 18:34 ` Richard G. Hash
  4 siblings, 0 replies; 7+ messages in thread
From: Oliver E. Cole @ 1994-11-07  2:52 UTC (permalink / raw)


 (CVANOVER@bamanet.ua.edu) writes:
> Is there a way to call a C++ procedure from within ADA? I can call a C 
> procedure with 
> 


  [snip]

   Norm Cohen was right in his response.  

   Please feel free to contact us at info@ocsystems.com if you have 
questions.  We support our university users ...

--oec

---
------------------------------------------------------------------------------
Oliver E. Cole                                               oec@ocsystems.com
OC Systems, Inc.                                                (703) 359-8165
-- 
------------------------------------------------------------------------------
Oliver E. Cole                                               oec@ocsystems.com
OC Systems, Inc.                                                (703) 359-8165



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

* Re: Calling C++ from within ADA
  1994-11-03 12:53 Calling C++ from within ADA CVANOVER
                   ` (2 preceding siblings ...)
  1994-11-07  2:52 ` Oliver E. Cole
@ 1994-11-08 15:22 ` Eric Beser
  1994-11-08 18:34 ` Richard G. Hash
  4 siblings, 0 replies; 7+ messages in thread
From: Eric Beser @ 1994-11-08 15:22 UTC (permalink / raw)


We call C++ from Ada by doing the following.

If the C++ object has been created before calling Ada, A "This Ptr"
needs
to be passed to the Ada for the object that is to be called. The This
Ptr
points to the object of reference.

If other objects needed to be accessed, you can do it by getting other
"This Ptr" pointers.
The calling interface from Ada to C++ has to be to an extern "C"
function.

However this function can be defined in the H file. The "This Ptr" is
used
to access class member functions from the calling interface.

The other rule is that no object can be called unless elaborated first.
This includes Ada and C++.

Hope this helps.


Eric Beser



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

* Re: Calling C++ from within ADA
  1994-11-03 12:53 Calling C++ from within ADA CVANOVER
                   ` (3 preceding siblings ...)
  1994-11-08 15:22 ` Eric Beser
@ 1994-11-08 18:34 ` Richard G. Hash
  4 siblings, 0 replies; 7+ messages in thread
From: Richard G. Hash @ 1994-11-08 18:34 UTC (permalink / raw)


In <CVANOVER.1.0007E49E@bamanet.ua.edu> CVANOVER@bamanet.ua.edu writes:
> Is there a way to call a C++ procedure from within ADA?
> I am using IBM AIX on an RS6000.

Unless I'm missing something you've got a link problem - both Ada
and C++ want control first (before main) for "elaboration" (and whatever
C++ calls it). A normal (AIX) C++ application uses /bin/xlC to link,
which actually creates a little tmp file with the cdtors table
in it, and links it in (you can see this being generated by munch if
you use "xlC -#").

You'll find that the crt0.o being linked in by C++ isn't the
one in /usr/lib/crt0.o, it's in /usr/lpp/xlC/lib/crt0.o, and it
has a call to "__C_runtime_startup()" in it.

We got around this by generating the ld script for the Ada program
(using an Ada main), and then linking in the generated cdtors
table and manually calling _C_runtime_startup () first thing
in our Ada main (we were linking in a C++ Dynatext library).

Yes, it's ugly; no, it's not portable; no, I can't even guarantee
it will always work (I just found _C_runtime_startup in crt0 and
said "hmm, looks suspicious, wonder what happens if you call it?").

If there is a cleaner solution then I would like to hear it (it took
me two months to convince Dynatext their library was in C++ (prior
versions were in C), and then all they said was "how about that?",
and didn't offer any solutions).

--
Richard G. Hash                                      email: rgh@shell.com
Shell Development Company, Bellaire Research Center  phone: (713) 245-7311
Member Team Ada                Free Ada94 compilers: cs.nyu.edu:/pub/gnat



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

end of thread, other threads:[~1994-11-08 18:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-11-03 12:53 Calling C++ from within ADA CVANOVER
1994-11-03 15:11 ` Norman H. Cohen
     [not found] ` <CypvDM.8q5@nntpa.cb.att.com>
1994-11-04 17:31   ` Greg Harvey
1994-11-04 17:46     ` Greg Harvey
1994-11-07  2:52 ` Oliver E. Cole
1994-11-08 15:22 ` Eric Beser
1994-11-08 18:34 ` Richard G. Hash

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