comp.lang.ada
 help / color / mirror / Atom feed
* ada import c function
@ 2009-04-28 20:45 s. ashen
  2009-04-28 21:18 ` Maciej Sobczak
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: s. ashen @ 2009-04-28 20:45 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ada import c function
  2009-04-28 20:45 ada import c function s. ashen
@ 2009-04-28 21:18 ` Maciej Sobczak
  2009-04-28 21:40 ` sjw
  2009-04-28 23:08 ` 459143320
  2 siblings, 0 replies; 11+ messages in thread
From: Maciej Sobczak @ 2009-04-28 21:18 UTC (permalink / raw)


On 28 Kwi, 22:45, "s. ashen" <spain.as...@gmail.com> wrote:

> does anyone know how to compile this program,

Try to make a regular library out of the C part and then just give it
to GNAT with -largs -lmylibrary options. It is cleaner than messing
with object files directly.

> i had tried many in many
> ways, but i can't do this.. always occurred some  errors.

It would be much easier for people here if you show what errors you
get. This way people would know how far you went and where exactly you
have failed.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ada import c function
  2009-04-28 20:45 ada import c function s. ashen
  2009-04-28 21:18 ` Maciej Sobczak
@ 2009-04-28 21:40 ` sjw
  2009-04-28 23:08 ` 459143320
  2 siblings, 0 replies; 11+ messages in thread
From: sjw @ 2009-04-28 21:40 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ada import c function
  2009-04-28 20:45 ada import c function s. ashen
  2009-04-28 21:18 ` Maciej Sobczak
  2009-04-28 21:40 ` sjw
@ 2009-04-28 23:08 ` 459143320
  2009-04-29 16:00   ` s. ashen
  2009-04-29 19:03   ` sjw
  2 siblings, 2 replies; 11+ messages in thread
From: 459143320 @ 2009-04-28 23:08 UTC (permalink / raw)


there are basically two ways 

gcc -c imported_function.c -o imported_function.o
gnat make use_of_import.adb 
gnat bind use_of_import.ali
gnat link use_of_import.ali imported_function.o

or the quick way 

gcc -c imported_function.c -o imported_function.o
gnat make use_of_import.adb -largs imported_function.o




In <6568256f-39cd-4757-a630-fe6e4a9a82fc@l16g2000pra.googlegroups.com>, "s. ashen" <spain.ashen@gmail.com> writes:
>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.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ada import c function
  2009-04-28 23:08 ` 459143320
@ 2009-04-29 16:00   ` s. ashen
  2009-04-29 19:03   ` sjw
  1 sibling, 0 replies; 11+ messages in thread
From: s. ashen @ 2009-04-29 16:00 UTC (permalink / raw)


On 29 Квіт  by uk_VT_linguist, 02:08,
459143...@att.net@worldnet.att.net (anon) wrote:
> there are basically two ways
>
> gcc -c imported_function.c -o imported_function.o
> gnat make use_of_import.adb
> gnat bind use_of_import.ali
> gnat link use_of_import.ali imported_function.o
>
> or the quick way
>
> gcc -c imported_function.c -o imported_function.o
> gnat make use_of_import.adb -largs imported_function.o
>

Great Thanks!!! All work.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ada import c function
  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
  1 sibling, 1 reply; 11+ messages in thread
From: sjw @ 2009-04-29 19:03 UTC (permalink / raw)


On Apr 29, 12:08 am, 459143...@att.net@worldnet.att.net (anon) wrote:
> there are basically two ways
>
> gcc -c imported_function.c -o imported_function.o
> gnat make use_of_import.adb

You need -c on this command, or it will try to link and fail.

> gnat bind use_of_import.ali
> gnat link use_of_import.ali imported_function.o
>
> or the quick way
         ^^^^^
         right

> gcc -c imported_function.c -o imported_function.o
> gnat make use_of_import.adb -largs imported_function.o



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ada import c function
  2009-04-29 19:03   ` sjw
@ 2009-04-29 23:04     ` anon
  2009-04-30 20:48       ` sjw
  0 siblings, 1 reply; 11+ messages in thread
From: anon @ 2009-04-29 23:04 UTC (permalink / raw)


simon.j.wright

>> gnat make use_of_import.adb

  should of been

    gnat compile use_of_import.adb

which is the best way to learn Ada because one reason there are other Ada 
systems out there  And newbees need to know they must compile then bind 
and finally link a program or library, unlike other languages. Plus the options 
can and do change from time to time that may interfer with the standard 
usage of "gnat make".  

  And I was being nice and said the second way was quicky, actually its 
the LAZY way! 



In <f35ff4f7-8653-4010-9368-be0a0893b0d1@y6g2000prf.googlegroups.com>, sjw <simon.j.wright@mac.com> writes:
>On Apr 29, 12:08=A0am, 459143...@att.net@worldnet.att.net (anon) wrote:
>> there are basically two ways
>>
>> gcc -c imported_function.c -o imported_function.o
>> gnat make use_of_import.adb
>
>You need -c on this command, or it will try to link and fail.
>
>> gnat bind use_of_import.ali
>> gnat link use_of_import.ali imported_function.o
>>
>> or the quick way
>         ^^^^^
>         right
>
>> gcc -c imported_function.c -o imported_function.o
>> gnat make use_of_import.adb -largs imported_function.o




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ada import c function
  2009-04-29 23:04     ` anon
@ 2009-04-30 20:48       ` sjw
  2009-04-30 21:32         ` Gautier
  0 siblings, 1 reply; 11+ messages in thread
From: sjw @ 2009-04-30 20:48 UTC (permalink / raw)


On Apr 30, 12:04 am, a...@anon.org (anon) wrote:
> simon.j.wright
>
> >> gnat make use_of_import.adb
>
>   should of been
>
>     gnat compile use_of_import.adb
>
> which is the best way to learn Ada because one reason there are other Ada
> systems out there  And newbees need to know they must compile then bind
> and finally link a program or library, unlike other languages.

There's a difference between learning Ada and learning an Ada build
system!

The Ada addition is the binding process, otherwise I see no difference
from a C build using gcc.

And a g++ build uses collect2 on at least some systems, which
certainly comes in the same place as Ada binding even if it doesn't do
quite the same thing.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: ada import c function
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Gautier @ 2009-04-30 21:32 UTC (permalink / raw)


sjw:

> And a g++ build uses collect2 on at least some systems, which
> certainly comes in the same place as Ada binding even if it doesn't do
> quite the same thing.

Jumping on the g++ subject: I am trying to build some (open source) 
project on Linux which requires the gnatlink option "--LINK=g++" because 
of the presence of some libraries depending on the c++ stdlib. Do you 
what Linux (Red Hat flavor) package to install in order to successfully 
link, instead of getting "gnatlink: Could not locate linker: g++" ?
TIA
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[flat|nested] 11+ messages in thread

* linking with g++ (was: ada import c function)
  2009-04-30 21:32         ` Gautier
@ 2009-04-30 23:42           ` Björn Persson
  2009-05-01  5:48             ` linking with g++ Gautier
  0 siblings, 1 reply; 11+ messages in thread
From: Björn Persson @ 2009-04-30 23:42 UTC (permalink / raw)


Gautier wrote:

> Jumping on the g++ subject: I am trying to build some (open source)
> project on Linux which requires the gnatlink option "--LINK=g++" because
> of the presence of some libraries depending on the c++ stdlib. Do you
> what Linux (Red Hat flavor) package to install in order to successfully
> link, instead of getting "gnatlink: Could not locate linker: g++" ?
> TIA

I don't know anything about --LINK but the RPM package that contains g++ is
gcc-c++.

-- 
Bj�rn Persson
PGP key A88682FD



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: linking with g++
  2009-04-30 23:42           ` linking with g++ (was: ada import c function) Björn Persson
@ 2009-05-01  5:48             ` Gautier
  0 siblings, 0 replies; 11+ messages in thread
From: Gautier @ 2009-05-01  5:48 UTC (permalink / raw)


Bj�rn Persson:

> I don't know anything about --LINK but the RPM package that contains g++ is
> gcc-c++.

That was it! Thanks a lot!!
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-05-01  5:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-28 20:45 ada import c function s. ashen
2009-04-28 21:18 ` Maciej Sobczak
2009-04-28 21:40 ` sjw
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

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