comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing C and Ada95
@ 2003-10-20 23:13 Antonio Martínez
  2003-10-21  2:02 ` David Marceau
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Antonio Martínez @ 2003-10-20 23:13 UTC (permalink / raw)


Hello group.

I'm trying to interface C and Ada95 using gcc and gnat. The question is,
Why I cannot use put_line in my function sumtwo ?

I have this 3 sources (these are very small...)

paquete.ads:
package Paquete is
   function sumtwo(X : in Integer) return Integer;
   pragma Export_Function(Internal=>sumtwo, External=>sumtwo);
end Paquete;


paquete.adb:
with Ada.Text_io; use Ada.Text_Io;
package body Paquete is
   function sumtwo(X : in Integer) return Integer is
   begin
      -- put_line("Hello");
      return X + 2;
   end sumtwo;
end Paquete;

progC.c:

#include <stdio.h>
int sumtwo();
int main() {
  int i = 3;
  printf("%i + 2 = %i\n", i, masdos(3));
  return 0;
}

Ok... now I compile like this:

gnatmake paquete.adb           -> generates paquete.ali & paquete.o
gcc progC.v paquete.o -o progC -> generates progC executable

and it works !!!!   Ok. Now, if I add the 5th line in the file
paquete.adb, which contains put_line("Hello"), the gcc says ...
paquete.o(.text+0x10): In function `sumtwo':

: referencia a `ada__text_io__put_line__2' sin definir
collect2: ld devolviᅵ el estado de salida 1

What is the problem? Do I have to export Ada.Text_IO in any matter?

Thank you.

--
Antonio Martï¿œnez




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

* Re: Interfacing C and Ada95
  2003-10-20 23:13 Interfacing C and Ada95 Antonio Martínez
@ 2003-10-21  2:02 ` David Marceau
  2003-10-21  4:57   ` sk
  2003-10-21 15:00 ` Stephen Leake
  2003-10-21 16:04 ` Antonio Martínez
  2 siblings, 1 reply; 7+ messages in thread
From: David Marceau @ 2003-10-21  2:02 UTC (permalink / raw)


Antonio Mart�nez wrote:
> 
> Hello group.
> 
> I'm trying to interface C and Ada95 using gcc and gnat. The question is,
> Why I cannot use put_line in my function sumtwo ?
> 
> I have this 3 sources (these are very small...)
> 
> paquete.ads:
> package Paquete is
>    function sumtwo(X : in Integer) return Integer;
>    pragma Export_Function(Internal=>sumtwo, External=>sumtwo);
> end Paquete;
> 
> paquete.adb:
> with Ada.Text_io; use Ada.Text_Io;
> package body Paquete is
>    function sumtwo(X : in Integer) return Integer is
>    begin
>       -- put_line("Hello");
>       return X + 2;
>    end sumtwo;
> end Paquete;
> 
> progC.c:
> 
> #include <stdio.h>
> int sumtwo();
> int main() {
adainit();

>   int i = 3;
>   printf("%i + 2 = %i\n", i, masdos(3));
adafinal();

>   return 0;
> }
> 
> Ok... now I compile like this:
> 
> gnatmake paquete.adb           -> generates paquete.ali & paquete.o
> gcc progC.v paquete.o -o progC -> generates progC executable
> 
> and it works !!!!   Ok. Now, if I add the 5th line in the file
> paquete.adb, which contains put_line("Hello"), the gcc says ...
> paquete.o(.text+0x10): In function `sumtwo':
> 
> : referencia a `ada__text_io__put_line__2' sin definir
> collect2: ld devolvi� el estado de salida 1
> 
> What is the problem? Do I have to export Ada.Text_IO in any matter?
> 
> Thank you.
> 
> --
> Antonio Mart�nez



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

* Re: Interfacing C and Ada95
  2003-10-21  2:02 ` David Marceau
@ 2003-10-21  4:57   ` sk
  0 siblings, 0 replies; 7+ messages in thread
From: sk @ 2003-10-21  4:57 UTC (permalink / raw)
  To: comp.lang.ada

David Marceau <davidmarceau@sympatico.ca>:
 > ... <David's additions> ...

and a library specification for linking "libgnat.a" or "libgnat.xx.so"

gcc <...> -L/usr/gnat/lib/<...>/adalib -lgnat

for example.


-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




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

* Re: Interfacing C and Ada95
  2003-10-20 23:13 Interfacing C and Ada95 Antonio Martínez
  2003-10-21  2:02 ` David Marceau
@ 2003-10-21 15:00 ` Stephen Leake
  2003-10-21 22:16   ` Simon Wright
  2003-10-21 16:04 ` Antonio Martínez
  2 siblings, 1 reply; 7+ messages in thread
From: Stephen Leake @ 2003-10-21 15:00 UTC (permalink / raw)


Antonio Mart�nez <amartinez@atc.ugr.es> writes:

> Now, if I add the 5th line in the file
> paquete.adb, which contains put_line("Hello"), the gcc says ...
> paquete.o(.text+0x10): In function `sumtwo':
> 
> : referencia a `ada__text_io__put_line__2' sin definir
> collect2: ld devolvi� el estado de salida 1

This is an installation problem; the linker can't find the gnat
libraries.

Make sure you have only gnat in your path, no other gcc tools.

If that doesn't work, delete and re-install gnat.

when you come back for help, let us know what OS you are using, and
what version of gnat.

-- 
-- Stephe



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

* Re: Interfacing C and Ada95
  2003-10-20 23:13 Interfacing C and Ada95 Antonio Martínez
  2003-10-21  2:02 ` David Marceau
  2003-10-21 15:00 ` Stephen Leake
@ 2003-10-21 16:04 ` Antonio Martínez
  2003-10-21 17:26   ` sk
  2 siblings, 1 reply; 7+ messages in thread
From: Antonio Martínez @ 2003-10-21 16:04 UTC (permalink / raw)


> David Marceau <davidmarceau@sympatico.ca>:
>  > ... <David's additions> ...
> 
> and a library specification for linking "libgnat.a" or "libgnat.xx.so"
> 
> gcc <...> -L/usr/gnat/lib/<...>/adalib -lgnat

Ok. If I compile as:

gcc  -Wall -L/usr/gnat/adalib -lgnat progC.c paquete.o

but without adainit() and adafinal() it created a a.out, but this
throws a segment violation.

Now, one step more, as you told me, I add adainit() and adafinal()
to my C code, but I cannot compile. I haven't found any .h C header
which contains these procedures.

I can see this .h headers in:

/usr/gnat/lib/gcc-lib/i686-pc-linux-gnu/2.8.1/adainclude

a-ada.a-ada.h  a-adaint.h  a-raise.h  a-types.h  config.h

but none if them contains any adainit() or adafinal() procedure.

What should I add to my progC.c code to let gcc compile ???

*** I have a Debian 3.0 with gcc 3.3.2 and gnat 3.15p installed.


Thank you. I promise I have tried many things to resolve this without
results.

--
Antonio Martï¿œnez




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

* Re: Interfacing C and Ada95
  2003-10-21 16:04 ` Antonio Martínez
@ 2003-10-21 17:26   ` sk
  0 siblings, 0 replies; 7+ messages in thread
From: sk @ 2003-10-21 17:26 UTC (permalink / raw)
  To: comp.lang.ada

Antonio Martï¿œnez <amartinez@atc.ugr.es>:
 > ... <snip> ...

Try section 2.11 of the "GNAT Users Guide" which you
should find in the "/use/gnat/doc" directory of a
Linux 3.15p installation.

A quick summary for your latest problem, create your
own header file for adainit and adafinal. This details
are in the guide.

-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




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

* Re: Interfacing C and Ada95
  2003-10-21 15:00 ` Stephen Leake
@ 2003-10-21 22:16   ` Simon Wright
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Wright @ 2003-10-21 22:16 UTC (permalink / raw)


Stephen Leake <Stephe.Leake@nasa.gov> writes:

> Antonio Mart�nez <amartinez@atc.ugr.es> writes:
> 
> > Now, if I add the 5th line in the file
> > paquete.adb, which contains put_line("Hello"), the gcc says ...
> > paquete.o(.text+0x10): In function `sumtwo':
> > 
> > : referencia a `ada__text_io__put_line__2' sin definir
> > collect2: ld devolvi� el estado de salida 1
> 
> This is an installation problem; the linker can't find the gnat
> libraries.

No, it's that he's using plain gcc to link rather than gnat tools.

This works for me (after including adainit(), adafinal() as a previous
poster suggested):

smaug.pushface.org[9]$ gnatmake -c paquete                         
gcc -c paquete.adb
smaug.pushface.org[10]$ gnatbind -n paquete.ali
smaug.pushface.org[11]$ gnatlink paquete.ali progC.o
smaug.pushface.org[12]$ ./paquete 
Hello
3 + 2 = 5

-- 
Simon Wright                               100% Ada, no bugs.



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

end of thread, other threads:[~2003-10-21 22:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-20 23:13 Interfacing C and Ada95 Antonio Martínez
2003-10-21  2:02 ` David Marceau
2003-10-21  4:57   ` sk
2003-10-21 15:00 ` Stephen Leake
2003-10-21 22:16   ` Simon Wright
2003-10-21 16:04 ` Antonio Martínez
2003-10-21 17:26   ` sk

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