Chapter 4. Dependency discovery — pkg-config

Table of Contents

1. File Format of *.pc Files
2. Dependencies
4. Additional Variables
5. Supporting Cross-Compilation

Discovering the presence of libraries through autoconf as described in Section 4, “Finding Libraries” is somewhat limiting; it does not allow for the library to provide specific information about the flags it needs to compile against (such as threading flags), nor does it allow us to properly pass other libraries we need to link to.

To work around these limitations, a number of projects started including simple scripts, called libname-config for the most part, that provided the flags and libraries needed to build against. Since each of these scripts used a different interface, they usually came with their own custom macro to call the script and store the resulting information in a variable.

Given the similitude of these scripts, the GNOME project created years ago an unified interface for them, in the form of the pkg-config command, that instead of including the data within the script uses simple text files to store and access it.

Nowadays, the script is used for much more than to simply discover the libraries and compiler flags, as it has grown to allow for special handling of static linking, and can provide data from arbitrary variables.