Jump to content

pkg-config

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Andrew Benton (talk | contribs) at 12:41, 15 December 2011 (→‎Synopsis). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

pkg-config
Original author(s)James Henstridge; rewritten by Havoc Pennington
Developer(s)Tollef Fog Heen / freedesktop.org
Initial release2006; 18 years ago (2006) or earlier
Stable release
0.26 / May 15, 2011 (2011-05-15)
Repository
Operating systemUnix-like
TypeProgramming tool
LicenseGNU GPL
Websitehttp://pkg-config.freedesktop.org/

pkg-config is computer software that provides a unified interface for querying installed libraries for the purpose of compiling software from its source code. pkg-config was originally designed for Linux but is now also available for the various BSDs, Microsoft Windows, Mac OS X, and Solaris.

It outputs various information about installed libraries. This information may include:

Synopsis

When a library is installed (automatically through the use of an RPM, deb, or other binary packaging system or by compiling from the source), a .pc file should be included and placed into a directory with other .pc files (the exact directory is dependent upon your system and outlined in the pkg-config man page). This file has several entries.

These entries typically contain a list of dependent libraries that programs using the package also need to compile. Entries also typically include the location of header files, version information and a description.

Here is an example .pc file for libpng:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${exec_prefix}/include
 
Name: libpng
Description: Loads and saves PNG files
Version: 1.2.8
Libs: -L${libdir} -lpng12 -lz
Cflags: -I${includedir}/libpng12

This file demonstrates how libpng informs that its libraries can be found in /usr/local/lib and its headers in /usr/local/include, that the library name is libpng, and that the version is 1.2.8. It also gives the additional linker flags that are needed to compile code that uses this library.

Here is an example of usage of pkg-config while compiling:

gcc -o test test.c $(pkg-config --libs --cflags libpng)