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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,633b377c6cd60b33,start X-Google-Attributes: gid103376,public From: hoffman@insync.net (David Hoffman) Subject: Need Help Calling Ada From C Date: 1998/12/05 Message-ID: #1/1 X-Deja-AN: 419063294 Content-transfer-encoding: 8bit Content-Type: text/plain; charset=ISO-8859-1 X-Complaints-To: news@insync.net X-Trace: insync 912898875 209.113.110.94 (Sat, 05 Dec 1998 17:01:15 CDT) Organization: Insync Internet Services, Inc. Mime-Version: 1.0 Reply-To: david.a.hoffman1@jsc.nasa.gov NNTP-Posting-Date: Sat, 05 Dec 1998 17:01:15 CDT Newsgroups: comp.lang.ada Date: 1998-12-05T00:00:00+00:00 List-Id: Hi, I am trying to figure out how to call an Ada function from a C program. For the record I am using GNAT 3.10p on Linux (Slackware, kernel 2.0.33). I read what I could find on the net, in the GNAT manual, and in several Ada books that I have. Since I did not find a complete, step-by-step ex- ample I had to make a few guesses (and maybe that is where things went wrong). I created a C program, called fact.c, that calls an Ada function from a package called first_test (the source code for these items is given at the end of this message). I compiled this with the commands: $ gcc -c first_test.ads $ gcc -c first_test.adb $ gnatbind -n first_test.ali $ gcc -c b_first_test.c $ gcc -c fact.c I made it this far without any real trouble. Then I got this: $ gcc -o fact *.o b_first_test.o: In function `adainit': b_first_test.o(.text+0x26): undefined reference to `__gnat_set_globals' b_first_test.o(.text+0x2e): undefined reference to `system__elabs' b_first_test.o(.text+0x33): undefined reference to `system__exception_table___elabb' b_first_test.o(.text+0x38): undefined reference to `interfaces__c___elabs' b_first_test.o(.text+0x3d): undefined reference to `system__tasking_soft_links___elabb' b_first_test.o(.text+0x42): undefined reference to `system__secondary_stack___elabb' fact.o: In function `main' fact.o(.text+0x30): undefined reference to `fact' Where did I go wrong? David Hoffman david.a.hoffman1@jsc.nasa.gov fact.c -------------------------------------------------------------------- extern void adainit(); extern void adafinal(); extern long factorial( long N ); main (argc, argv) char *argv[]; int argc; { long answer, value; adainit(); value = atol(argv[1]); if ( value 0 ) { if ( value <= 12 ) { answer = factorial(value); printf("\n %2d! = %3d\n",value,answer); } else { printf("\n fact: input value too big (would cause overflow).\n"); } } else { printf("\n fact: input must be strictly positive.\n"); } adafinal(); } first_test.ads --------------------------------------------------------- with Interfaces.C; use Interfaces; package First_Test is function Factorial ( Value : C.long ) return C.long; pragma Export (C, Factorial, "factorial"); end First_Test; first_test.adb --------------------------------------------------------- with Interfaces.C; use Interfaces; first_test.adb package body First_Test is function Ada_Factorial (N : Integer) return Integer is begin if N = 1 then return 1; else return N * Ada_Factorial(N-1); end if; end; function Factorial (Value : C.long) return C.long is P,Q : Integer; begin P := Integer(Value); Q := Ada_Factorial(P); return C.long(Q); end; end First_Test;