* Help with Gnat Cross-compile
@ 1998-04-13 0:00 Samuel G. Williams
1998-04-16 0:00 ` Ara Kassabian
0 siblings, 1 reply; 3+ messages in thread
From: Samuel G. Williams @ 1998-04-13 0:00 UTC (permalink / raw)
I am looking for good examples on two scenarios. The first is the compile of
Ada code for later linking in C. I would also like any recommendations for call
converntions. Second I am looking for the reverse. Being able to compile c
then link in with Ada also with the calling conventions. I am currently
attempting to help a friend without an Internet connection obtain this
information. I would welcome all replies. BTW he is using GNAT on a Solaris
workstation. He found brief entries in the GNAT UG but didn't quite
understand them well enough to be useful.
Thanks in advance for your help.
--
Sam Williams wb5yni samw@wwa.com
Systems Programmer Staff Specialist samw@sinnfree.org
---------------------------------------------------------------------------
simplicity is the ultimate form of sophistication....
Leonardo Da Vinci
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help with Gnat Cross-compile
1998-04-13 0:00 Help with Gnat Cross-compile Samuel G. Williams
@ 1998-04-16 0:00 ` Ara Kassabian
1998-04-17 0:00 ` Robert Dewar
0 siblings, 1 reply; 3+ messages in thread
From: Ara Kassabian @ 1998-04-16 0:00 UTC (permalink / raw)
Samuel G. Williams wrote:
>
> I am looking for good examples on two scenarios. The first is the compile of
> Ada code for later linking in C. I would also like any recommendations for call
> converntions. Second I am looking for the reverse. Being able to compile c
> then link in with Ada also with the calling conventions. I am currently
> attempting to help a friend without an Internet connection obtain this
> information. I would welcome all replies. BTW he is using GNAT on a Solaris
> workstation. He found brief entries in the GNAT UG but didn't quite
> understand them well enough to be useful.
>
> Thanks in advance for your help.
>
In Ada-83, interfacing with C was as easy as using the right pragmas, so long as
you didn't run into threading issues (both the C and Ada-83 parts of our program
were threaded, and the two threading packages were not aware of each other). It
*should* be just as easy with GNAT. The procedure should be:
1. Calling C from Ada: Write a package spec declaring the C functions and using
"pragma import", so Ada knows it needs to use C calling conventions.
2. Calling Ada95 from C: Write a header file with the Ada95 function/procedure
prototypes. If you cannot turn off name mangling in Ada95 using a pragma, then
you need to compile your files, figure out the mangled names by looking in the
object files and use those as your function names in your C header files. You
make things look pretty by using #define to create unmangled aliases for the
mangled functions. You *may* run into problems with Ada95 procedures. I am not
sure if they equate to void functions in C.
------------------------------------------------------
Ara Kassabian akass@worldnet.att.net
akassabian@logicon.com (work)
------------------------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help with Gnat Cross-compile
1998-04-16 0:00 ` Ara Kassabian
@ 1998-04-17 0:00 ` Robert Dewar
0 siblings, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1998-04-17 0:00 UTC (permalink / raw)
Ara said
<<In Ada-83, interfacing with C was as easy as using the right pragmas, so long as
you didn't run into threading issues (both the C and Ada-83 parts of our program
were threaded, and the two threading packages were not aware of each other). It
*should* be just as easy with GNAT. The procedure should be:
1. Calling C from Ada: Write a package spec declaring the C functions and using
"pragma import", so Ada knows it needs to use C calling conventions.
2. Calling Ada95 from C: Write a header file with the Ada95 function/procedure
prototypes. If you cannot turn off name mangling in Ada95 using a pragma, then
you need to compile your files, figure out the mangled names by looking in the
object files and use those as your function names in your C header files. You
make things look pretty by using #define to create unmangled aliases for the
mangled functions. You *may* run into problems with Ada95 procedures. I am not
sure if they equate to void functions in C.
>>
This is completely incorrect advice if you are using Ada 95. Things are
FAR simpler and FAR more portable in Ada 95, and indeed most of what you
need and want is right there in annex B in the RM. There is no need to
investigate mysterious system dependent "mangling" what ever that might be!
Indeed the advice as given in section 2 above is not even correct for Ada 83,
since it ignores elaboration issues, which often proved extremely difficult
to solve in Ada 83. Again in Ada 95, you can look in the RM to find out how
to handle the elaboration problem.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-04-17 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-13 0:00 Help with Gnat Cross-compile Samuel G. Williams
1998-04-16 0:00 ` Ara Kassabian
1998-04-17 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