4

I need to use the CUPS API in Qt to detect and install printers. The problem is I can't seem to make Qt detect the cups.h header file. So far I tried (both with <> and ""):

#include <cups/cups.h>

and

#include </usr/local/include/cups/cups.h>

In the .pro file I also tried adding:

INCLUDEPATH += /usr/local/include/cups

Each time I get "cups/cups.h: no such file or directory". So can anybody provide a minimal example or a HOWTO that shows how to include and use CUPS in a Qt application.

Thanks!

PS: I'am not sure if it's relevant, but I probably should add that I cross compiled Qt for the raspberry Pi.

luffy
  • 2,246
  • 3
  • 22
  • 28
  • Do you actually **have** `/usr/local/include/cups/cups.h` ? Considering that the explicit path apparently fails, it doesn't seem relevant that you use `qmake`. Your C++ compiler just can't find that file. – MSalters Feb 10 '15 at 12:50
  • /usr/local/include/cups/cups.h exists on my development machine but not on the target (Raspberry Pi). Do I have to cross compile CUPS along with Qt to be able to use it ? – luffy Feb 10 '15 at 13:07
  • 1
    You must install cups headers in your sysroot, looks like. – peppe Feb 10 '15 at 13:14
  • Thanks! Adding the headers to the sysroot worked, but now I get "undefined reference to `cupsGetDefault'...". I figured out it must be missing a library so I added "LIBS += -lcups" to my project file but it says "can't find -lcups"! – luffy Feb 10 '15 at 14:34
  • 1
    Libraries are not magic. It's just implementation, i.e. code. And you need to run that code on a RPi, so it better be RPi code. in the library – MSalters Feb 10 '15 at 16:23
  • possible duplicate of [How to add include path in Qt Creator?](http://stackoverflow.com/questions/2752352/how-to-add-include-path-in-qt-creator) – sashoalm Feb 11 '15 at 16:08
  • @MSalters you were absolutely right ! I was linking to the library in my development machine and not the raspberry one! A quick (find -name "\*cups.so\*") helped me locate the correct Lib. Thanks! – luffy Feb 12 '15 at 11:11
  • Why not list printer directly with [Qt Print Support](http://doc.qt.io/qt-5/qtprintsupport-index.html)? It works for me, I can list all printers set up in `cups`. – KernelPanic Jun 16 '16 at 06:48

1 Answers1

2

Install the "libcups2-dev" libraries.

 sudo apt-get install libcups2-dev

then search for the library file

find / -type f -name "*.a"

you will get the response with all .a library files with the location

find "libcups.a" file from the list.

example : /home/Desktop/cups-1.7.5/cups/libcups.a

Add the destination file path in your Qt .pro project file

LIBS += "../release/build/arm926/libcups.a"
tharunkumar
  • 2,801
  • 1
  • 16
  • 19