* Interfacing a subprogram from C.
@ 2002-02-28 15:11 Pedro Jose Garcia Gil
2002-02-28 17:50 ` sk
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Pedro Jose Garcia Gil @ 2002-02-28 15:11 UTC (permalink / raw)
Hello.
I want to use a function in C to program in Ada95.
For example (I have included all the realized steps.):
%%%%%%%%%%%% file "pepe.c" %%%%%
#include <stdio.h>
void pintar(int a){
printf("The number is : %d \n",a);
}
%%%%%%%%%%%%
$gcc -c pepe.c
%%%%%%%%%%% file prueba.adb %%%
with Ada.Text_IO; use Ada.Text_IO;
procedure prueba is
pragma linker_options("prueba.o");
procedure pintar(dato: integer);
pragma import(C,pintar,"pintar");
a: integer:=7;
begin
pintar(a);
end prueba;
%%%%%%%%%%%%%%
$gnatmake prueba.adb
>>>>>>>>>>>>>>>>>>>>>>>>>
gnatbind -x prueba.ali
gnatlink prueba.ali
prueba.o: In function `_ada_prueba':
prueba.o(.text+0x0): multiple definition of `_ada_prueba'
./prueba.o(.text+0x0): first defined here
./prueba.o: In function `_ada_prueba':
./prueba.o(.text+0x10): undefined reference to `pintar'
prueba.o: In function `_ada_prueba':
prueba.o(.text+0x10): undefined reference to `pintar'
gnatmake: *** link failed.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
What am I doing wrong?.
It's necessary to compile with other options or include some file in
somewhere?.
Thank you very much.
Pedro.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Interfacing a subprogram from C.
2002-02-28 15:11 Interfacing a subprogram from C Pedro Jose Garcia Gil
@ 2002-02-28 17:50 ` sk
2002-02-28 18:12 ` Pedro Garcia Gil
2002-02-28 18:15 ` Jerry van Dijk
2002-02-28 23:01 ` Jeffrey Carter
2 siblings, 1 reply; 5+ messages in thread
From: sk @ 2002-02-28 17:50 UTC (permalink / raw)
Hi,
1) Remove "pragma linker_options("prueba.o");" from the
Ada source.
2) use the command "gnatmake prueba.adb -largs pepe.o"
3) READ THE GNAT MANUALS :-)
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
k i e k c c m
-------------------------------------
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Interfacing a subprogram from C.
2002-02-28 15:11 Interfacing a subprogram from C Pedro Jose Garcia Gil
2002-02-28 17:50 ` sk
@ 2002-02-28 18:15 ` Jerry van Dijk
2002-02-28 23:01 ` Jeffrey Carter
2 siblings, 0 replies; 5+ messages in thread
From: Jerry van Dijk @ 2002-02-28 18:15 UTC (permalink / raw)
"Pedro Jose Garcia Gil" <pggil@isa.upv.es> writes:
> $gcc -c pepe.c
> What am I doing wrong?.
Your C object file is called pepe.o
> It's necessary to compile with other options or include some file in
> somewhere?.
More portable is:
*** c_part.c ***************************************************************
#include <stdio.h>
void c_part(int i)
{
printf("c_part received: %d\n", i);
}
****************************************************************************
*** ada_part.adb ***********************************************************
with Interfaces.C;
procedure Ada_Part is
procedure C_Part (I : Interfaces.C.int);
pragma Import (C, C_Part, "c_part");
pragma Linker_Options ("c_part.o");
begin
C_Part (7);
end Ada_Part;
****************************************************************************
****************************************************************************
C_PART C 87 28-02-02 19:07 c_part.c
ADA_PART ADB 213 28-02-02 19:10 ada_part.adb
C:\Home\work>gcc -c -o c_part.o c_part.c
C:\Home\work>gnatmake ada_part
gcc -c ada_part.adb
gnatbind -x ada_part.ali
gnatlink ada_part.ali
C:\Home\work>ada_part
c_part received: 7
****************************************************************************
--
-- Jerry van Dijk | email: jvandyk@attglobal.net
-- Leiden, Holland | web: users.ncrvnet.nl/gmvdijk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Interfacing a subprogram from C.
2002-02-28 15:11 Interfacing a subprogram from C Pedro Jose Garcia Gil
2002-02-28 17:50 ` sk
2002-02-28 18:15 ` Jerry van Dijk
@ 2002-02-28 23:01 ` Jeffrey Carter
2 siblings, 0 replies; 5+ messages in thread
From: Jeffrey Carter @ 2002-02-28 23:01 UTC (permalink / raw)
Pedro Jose Garcia Gil wrote:
>
> Hello.
>
> I want to use a function in C to program in Ada95.
>
> For example (I have included all the realized steps.):
>
> %%%%%%%%%%%% file "pepe.c" %%%%%
> #include <stdio.h>
> void pintar(int a){
> printf("The number is : %d \n",a);
> }
> %%%%%%%%%%%%
>
> $gcc -c pepe.c
>
> %%%%%%%%%%% file prueba.adb %%%
> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure prueba is
> pragma linker_options("prueba.o");
I suggest you want "pepe.o" here.
>
> procedure pintar(dato: integer);
> pragma import(C,pintar,"pintar");
> a: integer:=7;
>
> begin
> pintar(a);
> end prueba;
>
> %%%%%%%%%%%%%%
>
> $gnatmake prueba.adb
> >>>>>>>>>>>>>>>>>>>>>>>>>
> gnatbind -x prueba.ali
> gnatlink prueba.ali
> prueba.o: In function `_ada_prueba':
> prueba.o(.text+0x0): multiple definition of `_ada_prueba'
> ./prueba.o(.text+0x0): first defined here
> ./prueba.o: In function `_ada_prueba':
> ./prueba.o(.text+0x10): undefined reference to `pintar'
> prueba.o: In function `_ada_prueba':
> prueba.o(.text+0x10): undefined reference to `pintar'
> gnatmake: *** link failed.
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>
> What am I doing wrong?.
>
> It's necessary to compile with other options or include some file in
> somewhere?.
>
> Thank you very much.
>
> Pedro.
--
Jeffrey Carter
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-02-28 23:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-28 15:11 Interfacing a subprogram from C Pedro Jose Garcia Gil
2002-02-28 17:50 ` sk
2002-02-28 18:12 ` Pedro Garcia Gil
2002-02-28 18:15 ` Jerry van Dijk
2002-02-28 23:01 ` Jeffrey Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox