comp.lang.ada
 help / color / mirror / Atom feed
* Re: Help with some Code problems using C Interface
  2000-04-14  0:00 Help with some Code problems using C Interface Eric Bresie
@ 2000-04-14  0:00 ` Ted Dennison
  2000-04-16  0:00   ` Simon Wright
  2000-04-25  0:00 ` Erik Schalin
  1 sibling, 1 reply; 5+ messages in thread
From: Ted Dennison @ 2000-04-14  0:00 UTC (permalink / raw)


In article <38F742E3.71D536BE@arlut.utexas.edu>,
  Eric Bresie <bresie@arlut.utexas.edu> wrote:
> Okay...I am working on some ADA with some C function bindings.
>
> I have the following error being displayed when I compile the given
> code (spec and body) with the corresponding C code
> <errors>
> gnatbind -aO./ -aO. -I- -x tcim1.ali
> gnatlink -g tcim1.ali
> ./scsi_generic.o: In function `scsi_generic__inquiry':
> ./scsi_generic.adb:53: undefined reference to `scsi_inquiry'

This is usually a result of either specifying a slightly incorrect name
in the Ada interfacing pragma, or not linking against the object file
that contains the C routine. Judging from the gnatbind command, I'd say
its the latter. You need to reread the part of your compiler docs that
covers interfacing to C.


>         procedure SCSI_INQUIRY (
>                                 FD         : INTEGER;
>                                 LUN        : INTEGER;
>                                 INQ_BUFFER : SYSTEM.ADDRESS;
>                                 BYTECOUNT  : SYSTEM.ADDRESS;
>                                 ERROR      : SYSTEM.ADDRESS);
>         pragma INTERFACE (C, SCSI_INQUIRY);
>         pragma INTERFACE_NAME (SCSI_INQUIRY, "scsi_inquiry");

These are not Ada's standard C interfacing pragmas. They are custom ones
created by DEC for thier old Ada 83 VMS compiler, that Gnat included for
backwards compatability on that platform (even though they are now
redundant). I'm not saying you shouldn't use them. Just be advised that
if you do, this is not the correct place to ask questions about them.
You should go to the gnat-chat list instead. Here you're liable to get a
lot of responses that are unhelpful because people aren't familiar with
how these custom pragmas work.

The standard Ada way of doing this would be:
   pragma Import (C, SCSI_Inquiry, "scsi_inquiry");

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Help with some Code problems using C Interface
@ 2000-04-14  0:00 Eric Bresie
  2000-04-14  0:00 ` Ted Dennison
  2000-04-25  0:00 ` Erik Schalin
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Bresie @ 2000-04-14  0:00 UTC (permalink / raw)


Okay...I am working on some ADA with some C function bindings.

I have the following error being displayed when I compile the given code
(spec and body) with the corresponding C code

There are a number of similar problems, but I figured I would try and
handle one since the others should be the same.

I have included only the related code.  Hopefully you can see my method
of seperating the sections....I have XML in the brain at the moment :-)

I am sure this is a simple matter of a typo somewhere so any help would
be appreciated.

Eric Bresie
ebresie@usa.net

<errors>
gnatbind -aO./ -aO. -I- -x tcim1.ali
gnatlink -g tcim1.ali
./scsi_generic.o: In function `scsi_generic__inquiry':
./scsi_generic.adb:53: undefined reference to `scsi_inquiry'
gnatmake: *** link failed.

Compilation exited abnormally with code 4 at Fri Apr 14 10:33:48
</errors>

<code>
<ada>
<spec>

    function INQUIRY (FILE : OS_CALLS.FILE_DESCRIPTOR)
        return STRING;

</spec>
<body>
    -- scsi inquiry
    --
    function INQUIRY (
        FILE : OS_CALLS.FILE_DESCRIPTOR)
        return STRING
    is

        procedure SCSI_INQUIRY (
                                FD         : INTEGER;
                                LUN        : INTEGER;
                                INQ_BUFFER : SYSTEM.ADDRESS;
                                BYTECOUNT  : SYSTEM.ADDRESS;
                                ERROR      : SYSTEM.ADDRESS);
        pragma INTERFACE (C, SCSI_INQUIRY);
        pragma INTERFACE_NAME (SCSI_INQUIRY, "scsi_inquiry");

        INQ_BUFFER : STRING (1..200);
        ERROR      : INTEGER;
        LUN        : INTEGER := 0;
        CNT      : INTEGER := 0;
    begin

       SCSI_INQUIRY (INTEGER (FILE),   -- this is line 53 of
scsi_generic.adb
                     LUN,
                     INQ_BUFFER(1)'ADDRESS,
                     CNT'ADDRESS,
                     ERROR'ADDRESS);

        return INQ_BUFFER;

    end INQUIRY;

</body>
</ada>
<c>
<prototype>
/* scsi_inquiry(file descriptor, lun, buffer, error) */
void    scsi_inquiry (int, int, char *, int *, int *);
</prototype>
/*
 * SCSI inquiry command.
*/
void
scsi_inquiry (int fd, int lun, char * buffer, int *bytecount, int *
error)
{
    int i;
    static unsigned char scsi_command[INQUIRY_CMD_LEN];


    scsi_command[0] = INQUIRY_CMD;        /* command */
    scsi_command[1] = (lun << LUN_OFFSET_SHIFT);  /* lun/reserved
*/
    scsi_command[2] = 0;                  /* page code          */
    scsi_command[3] = 0;                  /* reserved           */
    scsi_command[4] = INQUIRY_REPLY_LEN;  /* allocation length  */
    scsi_command[5] = 0;                  /* reserved/flag/link */

    *error = sg_command (
        fd,
        scsi_command,        /* scsi command */
        INQUIRY_CMD_LEN,        /* command descriptor length */
        0,                   /* input buffer */
        0,                   /* input size */
        buffer,              /* output buffer */
        INQUIRY_REPLY_LEN);  /* output size */

    if ( *error >= 0 ) *bytecount = *error;

    for (i = 0; i < INQUIRY_REPLY_LEN - 8; i++)
       buffer[i] = buffer[i+8];
}


</c>
</code>





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

* Re: Help with some Code problems using C Interface
  2000-04-14  0:00 ` Ted Dennison
@ 2000-04-16  0:00   ` Simon Wright
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Wright @ 2000-04-16  0:00 UTC (permalink / raw)


Ted Dennison <dennison@telepath.com> writes:

> In article <38F742E3.71D536BE@arlut.utexas.edu>,
>   Eric Bresie <bresie@arlut.utexas.edu> wrote:
> > Okay...I am working on some ADA with some C function bindings.
> >
> > I have the following error being displayed when I compile the given
> > code (spec and body) with the corresponding C code
> > <errors>
> > gnatbind -aO./ -aO. -I- -x tcim1.ali
> > gnatlink -g tcim1.ali
> > ./scsi_generic.o: In function `scsi_generic__inquiry':
> > ./scsi_generic.adb:53: undefined reference to `scsi_inquiry'
> 
> This is usually a result of either specifying a slightly incorrect name
> in the Ada interfacing pragma, or not linking against the object file
> that contains the C routine. Judging from the gnatbind command, I'd say
> its the latter. You need to reread the part of your compiler docs that
> covers interfacing to C.

And the gnatmake command you should use probably looks something like

  gnatmake tcim1 -largs scsi_inquiry.o

ie you need to tell gnatmake where to find this function you've
invented. I'm assuming the file name convention, of course, perhaps
it's in scim1.o :-)

You might just possibly find it useful to look at pragma Link_Options
-- however, in my experience that's only really helpful for little
programs, as soon as things start being spread over multiple
directories, or if you have multiple libraries with order dependence,
it all breaks down.




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

* Re: Help with some Code problems using C Interface
  2000-04-14  0:00 Help with some Code problems using C Interface Eric Bresie
  2000-04-14  0:00 ` Ted Dennison
@ 2000-04-25  0:00 ` Erik Schalin
  2000-04-25  0:00   ` David Starner
  1 sibling, 1 reply; 5+ messages in thread
From: Erik Schalin @ 2000-04-25  0:00 UTC (permalink / raw)




Eric Bresie wrote:
> 
> Okay...I am working on some ADA with some C function bindings.
> 
> I have the following error being displayed when I compile the given code
> (spec and body) with the corresponding C code
> 
> There are a number of similar problems, but I figured I would try and
> handle one since the others should be the same.
> 
> I have included only the related code.  Hopefully you can see my method
> of seperating the sections....I have XML in the brain at the moment :-)
> 
> I am sure this is a simple matter of a typo somewhere so any help would
> be appreciated.
> 
> Eric Bresie
> ebresie@usa.net
> 
> <errors>
> gnatbind -aO./ -aO. -I- -x tcim1.ali
> gnatlink -g tcim1.ali
> ./scsi_generic.o: In function `scsi_generic__inquiry':
> ./scsi_generic.adb:53: undefined reference to `scsi_inquiry'
> gnatmake: *** link failed.
> 
> Compilation exited abnormally with code 4 at Fri Apr 14 10:33:48
> </errors>
> 
> <code>
> <ada>
> <spec>
> 
>     function INQUIRY (FILE : OS_CALLS.FILE_DESCRIPTOR)
>         return STRING;
> 
> </spec>
> <body>
>     -- scsi inquiry
>     --
>     function INQUIRY (
>         FILE : OS_CALLS.FILE_DESCRIPTOR)
>         return STRING
>     is
> 
>         procedure SCSI_INQUIRY (
>                                 FD         : INTEGER;
>                                 LUN        : INTEGER;
>                                 INQ_BUFFER : SYSTEM.ADDRESS;
>                                 BYTECOUNT  : SYSTEM.ADDRESS;
>                                 ERROR      : SYSTEM.ADDRESS);
>         pragma INTERFACE (C, SCSI_INQUIRY);
>         pragma INTERFACE_NAME (SCSI_INQUIRY, "scsi_inquiry");
> 
>         INQ_BUFFER : STRING (1..200);
>         ERROR      : INTEGER;
>         LUN        : INTEGER := 0;
>         CNT      : INTEGER := 0;
>     begin
> 
>        SCSI_INQUIRY (INTEGER (FILE),   -- this is line 53 of
> scsi_generic.adb
>                      LUN,
>                      INQ_BUFFER(1)'ADDRESS,
>                      CNT'ADDRESS,
>                      ERROR'ADDRESS);
> 
>         return INQ_BUFFER;
> 
>     end INQUIRY;
> 
> </body>
> </ada>
> <c>
> <prototype>
> /* scsi_inquiry(file descriptor, lun, buffer, error) */
> void    scsi_inquiry (int, int, char *, int *, int *);
> </prototype>
> /*
>  * SCSI inquiry command.
> */
> void
> scsi_inquiry (int fd, int lun, char * buffer, int *bytecount, int *
> error)
> {
>     int i;
>     static unsigned char scsi_command[INQUIRY_CMD_LEN];
> 
>     scsi_command[0] = INQUIRY_CMD;        /* command */
>     scsi_command[1] = (lun << LUN_OFFSET_SHIFT);  /* lun/reserved
> */
>     scsi_command[2] = 0;                  /* page code          */
>     scsi_command[3] = 0;                  /* reserved           */
>     scsi_command[4] = INQUIRY_REPLY_LEN;  /* allocation length  */
>     scsi_command[5] = 0;                  /* reserved/flag/link */
> 
>     *error = sg_command (
>         fd,
>         scsi_command,        /* scsi command */
>         INQUIRY_CMD_LEN,        /* command descriptor length */
>         0,                   /* input buffer */
>         0,                   /* input size */
>         buffer,              /* output buffer */
>         INQUIRY_REPLY_LEN);  /* output size */
> 
>     if ( *error >= 0 ) *bytecount = *error;
> 
>     for (i = 0; i < INQUIRY_REPLY_LEN - 8; i++)
>        buffer[i] = buffer[i+8];
> }
> 
> </c>
> </code>

Hi Eric

First question: Do you include the compiled c-file (.o)?
You should use:
pragma Linker_Option(filename.o);

second: ONLY use small letters, NOT THE BIG ONES. I do not know the
english term.
Ada only produce small letters, but c mix the
letters exactly as you write them.

Third: check the compiler reference manual.
look foor import_procedure. this might help.

four: export the c-code.

five: compile the c-code. use the unix command nm,
to see wich procedures is visible.

Maybe some of these hints will help

Erik




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

* Re: Help with some Code problems using C Interface
  2000-04-25  0:00 ` Erik Schalin
@ 2000-04-25  0:00   ` David Starner
  0 siblings, 0 replies; 5+ messages in thread
From: David Starner @ 2000-04-25  0:00 UTC (permalink / raw)


On Tue, 25 Apr 2000 18:25:39 +0200, Erik Schalin <erik.schalin@emw.ericsson.se> wrote:
>second: ONLY use small letters, NOT THE BIG ONES. I do not know the
>english term.
>Ada only produce small letters, but c mix the
>letters exactly as you write them.

No, he's got it right. While all capital letters aren't the best Ada style,
the important thing is that the case in the Import statement in the quotes
is right w/ regard to the C code, which it was in this case.

-- 
David Starner - dstarner98@aasaa.ofe.org

The hell that is supposedly out there could be no worse than
the hell that is sometimes seen in here.




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

end of thread, other threads:[~2000-04-25  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-14  0:00 Help with some Code problems using C Interface Eric Bresie
2000-04-14  0:00 ` Ted Dennison
2000-04-16  0:00   ` Simon Wright
2000-04-25  0:00 ` Erik Schalin
2000-04-25  0:00   ` David Starner

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