[sane-devel] I'm getting there...

Henning Meier-Geinitz henning@meier-geinitz.de
Sun, 21 Dec 2003 12:51:41 +0100


Hi,

On Sat, Dec 20, 2003 at 10:06:42PM -0500, Jason Anderson wrote:
> Here's the code from "hubba.c":

By the way: "hubba" ist just a stupid name like "foo". It's the sound
of the Marsupilami. In fact, it's "Houba!" in the original French
text.

> --------------
> #include <unistd.h>
> #include <stdlib.h>
> #include "../include/sane/sane.h"
> #include "../include/sane/config.h"
> #include "../include/sane/sanei.h"
> #include "../include/sane/sanei_usb.h"
> 
> /* Declare any prototypes */
> SANE_Status status;
> 
> int main(void) {
> 
> SANE_Int fd;
> 
> /* Start up the usb_interface */
> sanei_usb_init();
> 
> /* Try to access the usb device */
> status = sanei_usb_open("/dev/usb/scanner0",fd);

No. It's &fd. I've explained that in my last response, please read it
before going ahead. Also have a look at the documentation for
sanei_usb: http://www.sane-project.org/sanei/sanei__usb_8h.html

It says: sanei_usb_open (SANE_String_Const devname, SANE_Int *dn)

Mind the "*" (= pointer to a SANE_Int)!

> /* Check the status */
> if (status != SANE_STATUS_GOOD) {
>   return -1;
>     }
> /* Try to close the USB device */
> sanei_usb_close(fd);

That's ok. The declaration is:
sanei_usb_close (SANE_Int dn)

No "*", so it's ok.

> }

As you define main as an int ("int main(void) {"), you should add
"return 0;" here.

> And here's the error message I recieve:
> --------------
>  gcc hubba.c
> hubba.c: In function `main':
> hubba.c:27: warning: passing arg 1 of `sanei_usb_close' makes integer from pointer without a cast

No, that's not the message from the code above. That's the message
from the older code. sanei_usb_close is correct now.

> /tmp/ccWqpZ3d.o(.text+0x11): In function `main':
> : undefined reference to `sanei_usb_init'
> /tmp/ccWqpZ3d.o(.text+0x21): In function `main':
> : undefined reference to `sanei_usb_open'
> /tmp/ccWqpZ3d.o(.text+0x46): In function `main':
> : undefined reference to `sanei_usb_close'
> collect2: ld returned 1 exit status

That's because you didn't link against sanei_usb.

> Some have suggested just to use "&fd" in both of the functions
> (sanei_usb_open and sanei_usb_close).

Really? As far as I can see nobody on sane-devel did. It's wrong. You
must use the types of variables from the declarations. There is no
black magic involved.

> But I can't seem to link the file to another file such as
> "sanei_usb.lo".  I have given the full path to the file, but to no
> avail, such as in "gcc -l /path/to/object/file/ hubba.c".

I guess the easiest way is to place hubba.c in the tools/ directory
and add the following rule to the existing Makefile:

hubba: hubba.o ../sanei/sanei_usb.lo
	@$(LIBTOOL) $(MLINK) $(LINK) hubba.o $(LIBSANEI) $(LIBLIB)
	$(LIBS)
	
E.g. after the rule for sane-find-scanner. After that, just run 
"make hubba". For explanation of Makefiles, read "info make".

And please, stay in one therad. That means, please respond to the
answers given to you and don't start with a new subject every time.

Bye,
  Henning