Pkg-config

pkg-config is a helper tool which is used to obtain compiler & linker flags when building a package depending on a library.

libtool archives (.la files)
libtool uses specific archive file format (so-called .la files) to provide additional compiler and linker flags when linking against a library.

Implicit vs explicit use
libtool works implicitly whenever it is used to build a library or a program. In the former case, it creates the .la file with used flags; it latter, it reads those files and uses the flags stored in them.

pkg-config needs to be used explicitly. A library has to install .pc files explicitly, and the program built against it needs to query pkg-config explicitly in its build system.

Static vs dynamic linking
libtool provides no distinction between dynamic and static linking. In both cases, the complete list of dependant libraries is passed to linker.

pkg-config explicitly distinguishes between public and private dependencies. This way, when using dynamic linking only actually necessary libraries are passed to linker; and when using static linking, the complete list is used.

Build system-agnostic
libtool archives are usually useful only when libtool is used both to build the library and the final executable. pkg-config is designed to be build system-agnostic instead.

No absolute paths
For a long time Gentoo suffered an issue that libtool archives contained absolute paths to dependent library archives. Effectively, whenever libraries were moved to another library directory, all libraries depending on them became broken and required rebuild. Although the issue is currently worked-around in Gentoo by replacing absolute paths with relative library names, it is still the upstream behavior of libtool.

pkg-config expresses dependencies through package names, and thus is free by design of similar issues.

Custom -config applications
Many libraries provide custom applications of similar function, for example pcap-config. Those applications are compiled along with the library, and often have the relevant compiler & linker flags compiled into itself.

Cross-compilation support
Usually, custom -config applications are built for the specific platform the library is built for. Effectively, they are of no use when cross-compiling if the host is unable to execute code for the target platform.

pkg-config uses simple text files which are platform-independent. Thus, for cross-compilation to work it is only necessary to install pkg-config on the host system and set appropriate PKG_CONFIG_PATH.

Available implementations
In Gentoo, various implementations of pkg-config can be obtained.

Currently available implementations are:
 * — the official implementation; it requires which causes a circular dependency;
 * — an alternative implementation in ANSI C;
 * — OpenBSD implementation in Perl.