comp.lang.ada
 help / color / mirror / Atom feed
* Re: Interfacing Ada Routines in C
  1996-09-11  0:00 ` Greg Baker
@ 1996-09-11  0:00   ` Andy McNerney
  0 siblings, 0 replies; 4+ messages in thread
From: Andy McNerney @ 1996-09-11  0:00 UTC (permalink / raw)



Greg Baker <gbaker@walleroo.rp.csiro.au> wrote:

>>   Does anyone know how I can interface an Ada procedure in my
>> C program? 
>>   I've tried the following unsuccessfully:
>>   
>>   Compiled the ada procedure into an object file. Included
>> the ada object file during the link, but the compiler isn't
>> able to find the procedure referenced in my C program.
>> 
>>   BTW, I am using gcc and Sun Ada on a Solaris platform.
>
>The Ada compiler does some slight name mangling (it includes the name
>of the package in the link name). 
>Without checking too carefully..
>
>Ada:
> package Foo is
>   procedure Bar;
> end Foo;
>
>C:
>  extern void foo__bar();
>  

This, unfortunately, is an Appendix F issue.  The way I have had to do it, using 
gcc and gnat ADA, on an SGI is to use PRAGMA EXPORT within the ADA, so that the
C can see the symbol with the name of your choosing : Eg:


function create (bob : in bob_type) return integer;
PRAGMA EXPORT (c, create, External_Name => "create");

--------------------------------------------^^^^
This can be what ever you wish to call the routine as seen from the C.


Using VERDIX ada, also on SGI the synax is as follows:

function create (bob : in bob_type ) return integer;
PRAGMA external_name ( create, "create");


This aviods you 'hacking' the C to get it to work.

Hope this helps.

-------------------------------------------------------------------------
   Andrew A McNerney                   | 
   andy.mcnerney@gecm.com              | These are my personal opinions
   GEC Marconi S3i                     |  and NOT those of my employer.
   Simulation and Training Division    |
-------------------------------------------------------------------------






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

* Interfacing Ada Routines in C
@ 1996-09-11  0:00 Steven To
  1996-09-11  0:00 ` Greg Baker
  1996-09-11  0:00 ` Robert Dewar
  0 siblings, 2 replies; 4+ messages in thread
From: Steven To @ 1996-09-11  0:00 UTC (permalink / raw)




  Does anyone know how I can interface an Ada procedure in my
C program? 

  I've tried the following unsuccessfully:
  
  Compiled the ada procedure into an object file. Included
the ada object file during the link, but the compiler isn't
able to find the procedure referenced in my C program.

  BTW, I am using gcc and Sun Ada on a Solaris platform.


-- 

                                     Steven P. To
                                     sto@cs.ucr.edu
                                     http://www.cs.ucr.edu/~sto

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
 
mQBtAzEOPK0AAAEDALc8Eit5UcXOV8H2+6Pqp72tNvzhjJFEqEIWYCgZavvJ0OCd
16yuGky+Dd/xTwdg3W7npFc8aFV5z0hlst0MCisfMMGF0xGjLj86xOtxv+RlucOL
lLoBewWuHzJpCflffQAFE7QdU3RldmVuIFAuIFRvIDxzdG9AY3MudWNyLmVkdT4=
=5L9Q
-----END PGP PUBLIC KEY BLOCK-----


-- 

                                     Steven P. To
                                     sto@cs.ucr.edu
                                     http://www.cs.ucr.edu/~sto

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
 
mQBtAzEOPK0AAAEDALc8Eit5UcXOV8H2+6Pqp72tNvzhjJFEqEIWYCgZavvJ0OCd
16yuGky+Dd/xTwdg3W7npFc8aFV5z0hlst0MCisfMMGF0xGjLj86xOtxv+RlucOL
lLoBewWuHzJpCflffQAFE7QdU3RldmVuIFAuIFRvIDxzdG9AY3MudWNyLmVkdT4=
=5L9Q
-----END PGP PUBLIC KEY BLOCK-----





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

* Re: Interfacing Ada Routines in C
  1996-09-11  0:00 Interfacing Ada Routines in C Steven To
@ 1996-09-11  0:00 ` Greg Baker
  1996-09-11  0:00   ` Andy McNerney
  1996-09-11  0:00 ` Robert Dewar
  1 sibling, 1 reply; 4+ messages in thread
From: Greg Baker @ 1996-09-11  0:00 UTC (permalink / raw)



sto@cs.ucr.edu (Steven To) writes:
>   Does anyone know how I can interface an Ada procedure in my
> C program? 
> 
>   I've tried the following unsuccessfully:
>   
>   Compiled the ada procedure into an object file. Included
> the ada object file during the link, but the compiler isn't
> able to find the procedure referenced in my C program.
> 
>   BTW, I am using gcc and Sun Ada on a Solaris platform.

The Ada compiler does some slight name mangling (it includes the name
of the package in the link name). 
Without checking too carefully..

Ada:
 package Foo is
   procedure Bar;
 end Foo;

C:
  extern void foo__bar();
  
I derived the above information by compiling the foo package, and
running "nm foo.o | grep bar".  (Actually I did nothing of the sort,
I'm just going from memory).

Hope this helps.

-- 
Gregory D. Baker        gbaker@rp.csiro.au         CSIRO Radiophysics 
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
   - predictions of the future - quantum computers - silly poetry  -
   - the "langue musicale universale" (Solresol)  revival project  - 
   - - - - - - - - http://www.rp.csiro.au/~gbaker  - - - - - - - - -
I am about to leave CSIRO. The above email address and URL may become
                    invalid in October.




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

* Re: Interfacing Ada Routines in C
  1996-09-11  0:00 Interfacing Ada Routines in C Steven To
  1996-09-11  0:00 ` Greg Baker
@ 1996-09-11  0:00 ` Robert Dewar
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1996-09-11  0:00 UTC (permalink / raw)



Steven asks

"  Compiled the ada procedure into an object file. Included
the ada object file during the link, but the compiler isn't
able to find the procedure referenced in my C program."

You should read two things. First the documentation in gnatinfo.txt on
running when the main program is not Ada, if this applies.

Second the description of pragma Export. Your gave only sketchy details
but perhaps you are missing an external name argument on your Export
pragma.





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

end of thread, other threads:[~1996-09-11  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-11  0:00 Interfacing Ada Routines in C Steven To
1996-09-11  0:00 ` Greg Baker
1996-09-11  0:00   ` Andy McNerney
1996-09-11  0:00 ` Robert Dewar

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