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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,16656275b5169989 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-29 14:27:18 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: jeff.huter@bigfoot.com (Jeff) Newsgroups: comp.lang.ada Subject: Re: Link C main with Ada static library Date: 29 Nov 2002 14:27:18 -0800 Organization: http://groups.google.com/ Message-ID: References: NNTP-Posting-Host: 143.182.124.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1038608838 29561 127.0.0.1 (29 Nov 2002 22:27:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 29 Nov 2002 22:27:18 GMT Xref: archiver1.google.com comp.lang.ada:31318 Date: 2002-11-29T22:27:18+00:00 List-Id: Thanks. This seems to do the trick. However, it doesn't seem to be completely in accord with the description in the GNAT User's Manual for generating Ada libraries. In particular, the manual says to use the -L switch with gnatbind. Even in light of your solution, I have been unable to get it work using -L switch of gnatbind as outlined in the manual. But, your solution seems to work which is all that matters to me at this point. Thanks again -- Jeff sk wrote in message news:... > Hi, > > Tricky without seeing your "library" code, but this > works, GNAT 3.15p, Linux-Mandrake 8.2. > > -- static_ada_library.ads -- > package Static_Ada_Library is > > function Return_Forty_Two return Natural; > pragma Export (C, Return_Forty_Two, "return_forty_two"); > > end Static_Ada_Library; > > -- static_ada_library.adb -- > package body Static_Ada_Library is > > function Return_Forty_Two return Natural is > begin > return 42; > end Return_Forty_Two; > > end Static_Ada_Library; > > -- main.c -- > extern int return_forty_two (); > extern int adainit (); > extern int adafinal (); > > #include > > int main () { > > int i = 0; > > printf ("i => %d\n", i); > > > adainit (); > > i = return_forty_two (); > > adafinal (); > > printf ("i => %d\n", i); > > }; > > > Now the build ... > > # gnatmake -c static_ada_library > # gnatbind -n static_ada_library > > -- OR gnatbind -z ... > > # gcc -c b~static_ada_library.adb > # ar rc static_ada_library.a static_ada_library.o b~static_ada_library.o > # gcc main.c static_ada_library.a -o c-test \ > /usr/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adalib/libgnat.a > > # ./c-test > i => 0 > i => 42 > > -- > The above is very CRUDE, but it should point you in the right > direction. > > Review your "ld" manual to see how to link against > "libgnat.so" etc. > > Good luck. > > > -- For real address, merge vertically > ------------------- > -- s n p @ t . o > -- k i e k c c m > -------------------