error: Cannot find cairo.h

Introduction

When installing cairo package for R the following error might be thrown:

configure: error: Cannot find cairo.h! Please install cairo (http://www.cairographics.org/) and/or set CAIRO_CFLAGS/LIBS correspondingly.

The error is generated because cairo.h header file is missing. Follow the steps below to solve this issue on Ubuntu.

Solution

Installing libcairo2-dev package will solve the problem, because it will provide the missing cairo.h file.

This can be verified using the following command:

apt-file search --regex /cairo.h$

It will return the following result:

Now you can install the package:

sudo apt install libcairo2-dev

After installing libcairo2-dev package you might still get the following error (which was the case for me):

fatal error: X11/Intrinsic.h: No such file or directory

In this case install the following package as well:

sudo apt install libxt-dev

NOTE: if you don’t have apt-file installed follow these steps:

sudo apt install apt-file
sudo apt-file update

After that you will be able to run apt-file utility

Conclusion

After following the steps above I was able to install cairo package successfully and hope it will help you too.

Thank you for reading!

Tags: