Search code examples
cgccprintingcups

CUPS undefined reference to cupsGetDests()


I am trying to learn CUPS API development. For that I have installed CUPS 2.1.3-4 in my ubuntu 16.04.

When I try to execute their initial tutorial I am getting following error.

||=== Build: Debug in cupsfirst (compiler: GNU GCC Compiler) ===| obj/Debug/main.o||In function main':| /home/xxxx/CUPS/cupsfirst/main.c|8|undefined reference to cupsGetDests'| ||error: ld returned 1 exit status| ||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

This is my initial program.

#include <stdio.h>
#include <cups/cups.h>

int main(void)
{
  int i;
  cups_dest_t *dests, *dest;
  int num_dests = cupsGetDests(&dests);

  for (i = num_dests, dest = dests; i > 0; i --, dest ++)
  {
    if (dest->instance)
      printf("%s/%s\n", dest->name, dest->instance);
    else
      puts(dest->name);
  }

  return (0);
}

Solution

  • You need to install the CUPS library, the dev package (you have it already I suppose)

    apt install libcups2 libcups2-dev
    

    to compile then link, include the cups2 library

    gcc myprog.c -o myprog -lcups