comp.lang.ada
 help / color / mirror / Atom feed
From: sk <sk@noname.com>
Subject: Re: Link C main with Ada static library
Date: Fri, 29 Nov 2002 04:04:05 -0600
Date: 2002-11-29T04:04:05-06:00	[thread overview]
Message-ID: <mailman.1038564541.20930.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: fe4bb2c2.0211290045.dba25a4@posting.google.com

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 <stdio.h>

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




  reply	other threads:[~2002-11-29 10:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-29  8:45 Link C main with Ada static library Jeff
2002-11-29 10:04 ` sk [this message]
2002-11-29 22:27   ` Jeff
2002-11-29 23:25     ` sk
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox