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.cpp
I 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.h
Info about system:
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trusty
Output 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
apt-file search
gives the informationBecause of that execute
and compile with
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.You 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.-lcairo
tells the linker to search for a library calledcairo
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, afterscreenshot.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.