[cups.development] Link error when compiling with backend API

Michael Sweet msweet at apple.com
Tue Mar 29 12:07:07 PDT 2011


On Mar 29, 2011, at 5:56 AM, bui wrote:
> Hi,
> 
> I am trying to use cupsBackendDeviceURI API to retrieve the printer URI. Unfortunately I get the " undefined reference to `cupsBackendDeviceURI(char**)" when compiling
> 
> My code is:
> 
>        char *backend = "usb";
>        const char	*uri;
>       uri = cupsBackendDeviceURI(&backend);

This code can't work; cupsBackendDeviceURI is only valid when called *from a backend*. It cannot be used from user programs, and certainly not with a single character pointer like that - the input is the argv[] array passed to a backend program, so at the very least you need a 2 element array with the last pointer being NULL...


> 
> Below is the linker output:
> /home/bao/work/buildroot/output/staging/usr/bin/arm-unknown-linux-uclibcgnueabi-g++ --sysroot=/home/bao/work/buildroot/output/staging -L/home/bao/work/buildroot/output/staging/lib -L/home/bao/work/buildroot/output/staging/usr/lib -Wl,-O1 -o AutoPrint WidgetKeyboard.o Main.o autoprint.o cupshelper.o moc_WidgetKeyboard.o moc_autoprint.o qrc_WidgetKeyboard.o -L/home/bao/work/buildroot/output/staging/usr/lib -lcups -lQtGui -L/home/bao/work/buildroot/output/staging/usr/lib -lQtNetwork -lQtCore -lpthread -lcupsdriver

Did you include <cups/backend.h> to get the definition of the function?

> 
> 
> 
> /home/bao/work/buildroot/output/staging/usr/lib/libcups.so: warning: gethostbyname is obsolescent, use getnameinfo() instead.
> /home/bao/work/buildroot/output/staging/usr/lib/libglib-2.0.so.0: warning: the use of OBSOLESCENT `utime' is discouraged, use `utimes'
> autoprint.o: In function `autoprint::printerSelected(int)':
> autoprint.cpp:(.text+0x800): undefined reference to `cupsBackendDeviceURI(char**)'
> collect2: ld returned 1 exit status
> 
> 
> Any help?
> 
> Thanks
> _______________________________________________
> cups-dev mailing list
> cups-dev at easysw.com
> http://lists.easysw.com/mailman/listinfo/cups-dev

________________________________________________________________________
Michael Sweet, Senior Printing System Engineer, PWG Chair





More information about the cups-devel mailing list