[sane-devel] Compiling test program against libsane

Albert ARIBAUD albert.aribaud at free.fr
Fri Jul 6 22:19:01 UTC 2012


Le 06/07/2012 22:28, Jeffrey Ratcliffe a écrit :
> I'm trying to track down a bug, which I think is in HPLIP, and I have
> this test program, which compiles and runs fine on my gentoo box:
>
> #include <stdio.h>
> #include <sane/sane.h>
>
> int
> main (int argc, char **argv) {
>   SANE_Status		status;
>   SANE_Int		version_code;
>   SANE_Auth_Callback	authorize;
>   SANE_Handle 		h;
>   const SANE_Device	**device_list;
>
>   int i = atoi(argv[2]);
>
>   printf("initialising sane... ");
>   status = sane_init(&version_code, authorize);
>   printf("%s\n", sane_strstatus (status));
>
>   printf("opening %s, %d times\n", argv[1], i);
>
>   while (i-- > 0) {
>     printf("opening %s... ", argv[1]);
>     status = sane_open(argv[1], &h);
>     printf("%s\n", sane_strstatus (status));
>
>     sane_close(h);
>   }
>   sane_exit;
> }
>
> However, on my Ubuntu Precise box, I'm getting:
>
> $ gcc -lsane -L/usr/lib/i386-linux-gnu/ -I/usr/include/
> hplip_segfault.c -o hplip_segfault
> /tmp/cciw9jNN.o: In function `main':
> hplip_segfault.c:(.text+0x3a): undefined reference to `sane_init'
> hplip_segfault.c:(.text+0x4a): undefined reference to `sane_strstatus'
> hplip_segfault.c:(.text+0xa6): undefined reference to `sane_open'
> hplip_segfault.c:(.text+0xb6): undefined reference to `sane_strstatus'
> hplip_segfault.c:(.text+0xca): undefined reference to `sane_close'
> collect2: ld returned 1 exit status
>
> where the contents of /usr/lib/i386-linux-gnu/pkgconfig/sane-backends.pc is
>
> prefix=/usr
> exec_prefix=${prefix}
> libdir=${prefix}/lib/i386-linux-gnu
> includedir=${prefix}/include
> ldflags=-Wl,-Bsymbolic-functions
> libs=
>
> Name: SANE Backends
> Description: Backends for SANE, the universal scanner interface
> Version: 1.0.22
> Requires:
> Libs: -L${libdir} -lsane
> Libs.private: ${ldflags} ${libs}
> Cflags: -I${includedir}
>
> Has anyone any insight on how to get this linking properly?

Try to move the -lsane at the end of the command line :

gcc -L/usr/lib/i386-linux-gnu/ -I/usr/include/
 > hplip_segfault.c -o hplip_segfault -lsane

Don't know if that'll work for you, but I did have a similar issue with 
libusb where both -L and -l options were at the beginning, and moving 
the -l option at the end solved it.

> Regards
>
> Jeff

Amicalement,
-- 
Albert.





More information about the sane-devel mailing list