comp.lang.ada
 help / color / mirror / Atom feed
From: sjw <simon.j.wright@mac.com>
Subject: Re: ada import c function
Date: Tue, 28 Apr 2009 14:40:51 -0700 (PDT)
Date: 2009-04-28T14:40:51-07:00	[thread overview]
Message-ID: <8e93ef24-fe80-4098-9b41-bd8a4adfd8d2@z8g2000prd.googlegroups.com> (raw)
In-Reply-To: 6568256f-39cd-4757-a630-fe6e4a9a82fc@l16g2000pra.googlegroups.com

On Apr 28, 9:45 pm, "s. ashen" <spain.as...@gmail.com> wrote:
> Does anyone import C function to ada??
> Using gnat 3.15, i try to compile the example which contain two files
>   use_of_import.adb
>
> procedure Use_Of_Import is
>    procedure Imported_Function;
>    pragma Import (C, Imported_Function, "imported_function");
> begin
>    Imported_Function;
> end Use_Of_Import;
>
>   imported_function.c
>
> #include <stdio.h>
> imported_function ()
> {
>   printf ("\nI am now in the imported function\n\n");
>
> }
>
> does anyone know how to compile this program, i had tried many in many
> ways, but i can't do this.. always occurred some  errors.

nidhoggr:tmp simon$ gcc -c imported_function.c
nidhoggr:tmp simon$ gnatmake use_of_import.adb -largs
imported_function.o
gcc -c use_of_import.adb
gnatbind -x use_of_import.ali
gnatlink use_of_import.ali imported_function.o
nidhoggr:tmp simon$ ./use_of_import

I am now in the imported function

nidhoggr:tmp simon$

There are ways of doing this with GNAT project files but they would
take a while to explain -- and anyway I don't think 3.15 has GNAT
project? or if it does it's the first version ever. Upgrade if you can.



  parent reply	other threads:[~2009-04-28 21:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-28 20:45 ada import c function s. ashen
2009-04-28 21:18 ` Maciej Sobczak
2009-04-28 21:40 ` sjw [this message]
2009-04-28 23:08 ` 459143320
2009-04-29 16:00   ` s. ashen
2009-04-29 19:03   ` sjw
2009-04-29 23:04     ` anon
2009-04-30 20:48       ` sjw
2009-04-30 21:32         ` Gautier
2009-04-30 23:42           ` linking with g++ (was: ada import c function) Björn Persson
2009-05-01  5:48             ` linking with g++ Gautier
replies disabled

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