0

Found this link to a c script that claims to take a screenshot of the running machine, so I copied it and installed all that libraries needed for compiling this file

Hereyou can find info on how to to install the cairo lib

I am using gcc to compile the script and I tried compiling using the following commands

gcc -I/usr/include/cairo -lcairo -lX11 pic.c
gcc -I/usr/include/cairo -lX11 pic.c
gcc -Wall -I/usr/include/cairo -lm -lX11 pic.c

This is what i get when compiling

/usr/bin/ld: /tmp/ccOh9u2g.o: in function `main':
pic.c:(.text+0x91): undefined reference to `XOpenDisplay'
/usr/bin/ld: pic.c:(.text+0x15e): undefined reference to `cairo_xlib_surface_create'
/usr/bin/ld: pic.c:(.text+0x175): undefined reference to `cairo_surface_write_to_png'
/usr/bin/ld: pic.c:(.text+0x181): undefined reference to `cairo_surface_destroy'
collect2: error: ld returned 1 exit status

this is what i am using

Target: x86_64-linux-gnu
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 

1 Answers1

0

You need to mention the libraries after the source files, so that the compiler knows where to look for the dependencies. In other words, the linker will search the libraries placed after the source file, for the functions called from the source file.

Something like

gcc -I/usr/include/cairo pic.c -lcairo -lX11
gcc -I/usr/include/cairo helloworld.c -lX11 
gcc -Wall -I/usr/include/cairo helloworld.c -lm -lX11 

should do the job.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261