comp.lang.ada
 help / color / mirror / Atom feed
From: Andy McNerney <andy.mcnerney@gecm.com>
Subject: Re: Interfacing Ada Routines in C
Date: 1996/09/11
Date: 1996-09-11T00:00:00+00:00	[thread overview]
Message-ID: <515ug1$6ne@gcsin3.geccs.gecm.com> (raw)
In-Reply-To: 85u3t5wr8q.fsf@walleroo.rp.CSIRO.AU


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    |
-------------------------------------------------------------------------






      reply	other threads:[~1996-09-11  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-11  0:00 Interfacing Ada Routines in C Steven To
1996-09-11  0:00 ` Robert Dewar
1996-09-11  0:00 ` Greg Baker
1996-09-11  0:00   ` Andy McNerney [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