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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,52882f38318f3520 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Linking an ADA routine to a program written in C Date: 1996/09/19 Message-ID: <01bba5e0$cf06b040$328371a5@dhoossr.iquest.com>#1/1 X-Deja-AN: 181526630 distribution: world references: <51p2vu$enf@lal.interserv.com> content-type: text/plain; charset=ISO-8859-1 organization: DBH Enterprises, Inc. mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-09-19T00:00:00+00:00 List-Id: newmans@ncr.disa.mil wrote in article <51p2vu$enf@lal.interserv.com>... > > I desperately need an explanation of how to link a routine written and compiled in ADA into a program > written in C. For example, I built an ada test procedure hello.a and compiled it using the ada compiler. > The object file produced was called hello01. This program uses TEST_IO package to do the output. > > Since the object module hello01 is ELF-32 bit I linked it in with my C objects using gcc. But of course, > I get undefined symbols because I have no idea how to tell gcc about the TEST_IO package. > > Does anyone know how this can be done. > > Also, some people have mentioned that I may have to use a PRAGMA in my C code to tell the > compiler that the routine I am calling i.e. "hello" is not a C subroutine. C passes arguments from > right to left. I believe ADA probably passes them like PASCAL from left to right. In C you can declare > a routine to be type pascal to change the calling sequence to match PASCAL's. If anyone has > any experience calling ADA routines from C please contact me ASAP. > > Thank you! > This is an implementation-dependent thing. Generally what has to be done is to tell the Ada compiler that the routine is to be called by a C compilation unit. This is done with a pragma such a EXPORT or EXTERNAL, depending on the implementation. Consult your compiler documentation, looking especially for discussions of Interface Programming. Further, the issue of "withed" packages pretty much requires that your main program be an Ada program. If you already have a suitable "main" program written in C, you would need to put an Ada "wrapper" around the C main. The C main might have to be renamed, depending on the Ada implementation, because some Ada systems use a routine called "main", which would confuse the linker of there were two "main" symbols declared. The Ada main program also allows the elaboration code for each compilation unit to be called before the main program begins execution. The only kind of Ada unit which can be called from C is one in which there is NO elaboration code in the unit, or in any of the other Ada units it "withs". Hope these ramblings are helpful. -- David C. Hoos, Sr., http://www.dbhwww.com http://www.ada95.com