I've installed cairo-1.4.14 using make install, but after trying to compile my code:
fatal error: cairo.h: No such file or directory #include <cairo.h> ^I compile using this:
g++ screenshot.cppI installed 3 packages from this output, but still the same problem:
apt-file search --regex /cairo.h$
libcairo2-dev: /usr/include/cairo/cairo.h
r-cran-rgtk2: /usr/lib/R/site-library/RGtk2/include/RGtk2/cairo.h
thunderbird-dev: /usr/include/thunderbird/cairo/cairo.hInfo about system:
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trustyOutput of pkg-config --libs --cflags cairo :
-I/usr/local/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -L/usr/local/lib -lcairo 6 2 Answers
apt-file search gives the information
$ apt-file search --regex /cairo.h$
libcairo2-dev: /usr/include/cairo/cairo.hBecause of that execute
sudo apt install libcairo2-devand compile with
g++ screenshot.cpp $(pkg-config --libs --cflags cairo) 5 Unless you have a need for a Cairo version different from what Ubuntu supplies, please follow A.B.'s answer.
If you want to use the Cairo you installed manually, do as follows.
The problem is that libcairo installs its cairo.h to /usr/local/include/cairo/ and not /usr/local/include/ (i.e. one directory deeper)
You must pass this directory to the compiler with the -I switch.
g++ -I/usr/local/include/cairo/ -o screenshot screenshot.cppYou will probably run into a linker error then -- the linker doesn't know to search for libcairo and errors on unresolved symbols. So let's give g++ a couple of more parameters.
g++ -I/usr/local/include/cairo/ -L/usr/local/lib -o screenshot screenshot.cpp -lcairo-lcairo tells the linker to search for a library called cairo and -L/usr/local/lib gives the linker an extra directory to search from.
Note that the parameter order matters with -l -- it should be placed after the source or object files.[1] (In this case, after screenshot.cpp)
This should be enough for compiling your binary.
pkg-config is a tool for automating these things. It gives you the command-line parameters necessary to compile a program using a specific library. I think it often overshoots and ends up linking against multiple libraries that aren't actually needed. The manual way is better in that matter.
[1] Or so I think. I honestly can't grasp what that manual page of GCC is trying to say.
7