Home Contact Me Tutorials

Using Cairo With GDI



This guide explains what is needed to setup and create a C++ simple program that uses the Cairo Graphics Library and Windows GDI. This guide uses the Windows API, MinGW and Dev-C++. Readers who use Visual C++ or Code::Blocks will have to customize the instructions to suit their needs.

The following is a screenshot of the program. It displays one of the samples on the Cairo website. The download section of this guide provides a ZIP file that contains the sample program.

Build Dependencies

Static Libraries

The following files are needed when building a Cairo application using MinGW.

You should be able to get it from the Inkscape Win32 Support page. Download the file that has a name like cairo-X.X.X-mingw.7z, unzip it with 7-Zip and look inside the lib directory. MinGW users can link to this file by specifying the following in the linker options. Just make sure the file's directory is visible in the linker path.


Header Files

The cairo-X.X.X-mingw.7z archive also contains all the Cairo header files inside the include/cairo directory. Ensure that you add this directory in your compiler's include path while building.

Here's what my Dev-C++ compiler settings look like:

Runtime Dependencies

To run your Cairo program, make sure the following DLLs are in the same directory as your executable. You should be able to get them if you install the Windows port of GIMP, the GNU Image Manipulation Program. The DLLs are located in the bin directory.

Alternatively, you should also be able to get them from the official GTK+ download site - http://www.gtk.org/download-windows.html

The following picture shows the sample executable (cairo-gdi-demo.exe) in the same directory as all the other DLLs.

You could also put these DLLs inside the Windows system directory, instead of copying it to the same directory as every executable that needs them. However, I advise you not to do so, as it may lead to versioning problems in the future.


The following ZIP file contains all the files needed to build and run the sample program using Dev-C++. A pre-built executable is already included in the bin directory.