{{Short description|Software development tool for querying library dependency information}} {{lowercase title|title=pkg-config}} {{Infobox software | name = pkg-config | title = pkg-config | logo = <!-- Image name is enough --> | logo caption = | logo_size = | logo_alt = | screenshot = <!-- Image name is enough --> | caption = | screenshot_size = | screenshot_alt = | collapsible = | author = James Henstridge; rewritten by Havoc Pennington | developer = Tollef Fog Heen / freedesktop.org | released = {{Start date and age|2000}} or earlier | repo = {{URL|https://gitlab.freedesktop.org/pkg-config/pkg-config}} | discontinued = | latest release version = 0.29.2 | latest release date = {{Start date and age|2017|03|20}} | latest preview version = | latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} --> | programming language = C | operating system = Unix-like | platform = | size = | language = | language count = <!-- DO NOT include this parameter unless you know what it does --> | language footnote = | genre = Programming tool | license = GNU GPL | alexa = | website = {{URL|https://www.freedesktop.org/wiki/Software/pkg-config/}} | standard = | AsOf = }} {{Portal|Computer programming|Free and open-source software}} '''pkg-config''' is a software development tool that queries information about libraries from a local, file-based database for the purpose of building a codebase that depends on them. It allows for sharing a codebase in a cross-platform way by using host-specific library information that is stored outside of yet referenced by the codebase. This indirection allows the codebase to build on a host without encoding host-specific library information in the codebase.

The tool is invoked via its command line interface (CLI), and it reports library information via standard output. Some information, such as version information, is more useful to the programmer. Other information, such as command-line options (flags), is more useful to build tools such as a compiler and a linker.

The tool was originally designed for Linux, and is now also available for BSD, Windows, macOS, and Solaris. The first implementation was written in shell script.<ref>{{cite web |url=https://mail.gnome.org/archives/gtk-devel-list/2000-June/msg00023.html |title=Re: the *-config scripts |author=Havoc Pennington |date=4 June 2000 |access-date=2020-01-22 }}</ref> Later, it was rewritten in C leveraging GLib.<ref>{{cite web |url=https://mail.gnome.org/archives/gtk-devel-list/2000-July/msg00295.html |title=pkg-config |author=Havoc Pennington |date=23 July 2000 |access-date=2020-01-22 }}</ref>

== Database ==

To enable use of the tool, a referenced library must have a corresponding <code>.pc</code> file stored in the file system location designated for that purpose (the location varies by system). This file should be stored as part of the installation process as handled by RPM, deb, or other packaging system or by compiling from source code.

A <code>.pc</code> file contains various information such as the location of header files, library binaries and various descriptive information. It may also include a list of dependent libraries that programs using the library need to use.

==Example==

The following example <code>.pc</code> file defines information for libpng. It starts with defining variables that are used throughout the rest of the file. It includes descriptive information including name "libpng" and version "1.2.8". The <code>Cflags</code> entry defines an option that the C preprocessor uses to locate the library's header files {{endash}} in <code>/usr/local/include/libpng12</code>. The <code>Libs</code> entry defines options that define the location of library binaries, <code>/usr/local/lib</code>, and identify which library binary files to link.

<syntaxhighlight lang="pkgconfig"> 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 </syntaxhighlight>

The following is an example build command that uses this file to specify options to gcc. The output of command <code>pkg-config --libs --cflags libpng</code> is passed to gcc via its command line interface.

<syntaxhighlight lang="console"> $ gcc -o test test.c $(pkg-config --libs --cflags libpng) </syntaxhighlight>

== Alternative implementations ==

Notable variants of pkg-config:

* pkgconf &ndash; Re-write to eliminate GLib dependency; default (instead of pkg-config) on linux and BSD distributions from many vendors, including Alpine Linux,<ref name="repology">Found on [https://repology.org/project/pkgconf/versions spread of pkgconf] but not [https://repology.org/project/pkg-config/versions spread of pkg-config] on repology</ref> Arch Linux,<ref name="mail">https://lists.archlinux.org/pipermail/arch-dev-public/2018-May/029252.html Replacing pkg-config with pkgconf] on [https://lists.archlinux.org/listinfo arch-dev-public@lists.archlinux.org]</ref> CentOS 8+,<ref name="repology" /> Debian,<ref name="repology"/> Fedora,<ref name="mail" /> FreeBSD,<ref name="mail" /> Mageia 7+,<ref name="repology" /> Manjaro<ref name="repology" /> and NetBSD<ref name="mail" /> * u-config &ndash; First-class Windows support * PkgConfig &ndash; Written in Perl * ruby-gnome/pkg-config &ndash; Written in Ruby

== References == {{reflist}}

== External links == * [http://pkg-config.freedesktop.org/ pkg-config home at freedesktop.org] * {{man|1|pkg-config|die.net}} * {{man|1|pkg-config|OpenBSD}} * [https://github.com/pkgconf/pkgconf pkgconf] * [https://github.com/skeeto/u-config u-config] * [https://metacpan.org/release/PkgConfig PkgConfig] * [https://github.com/ruby-gnome/pkg-config ruby-gnome/pkg-config]

Category:Computer libraries Category:Freedesktop.org Category:Linux configuration utilities