Pkg-config

Last updated
pkg-config
Original author(s) James Henstridge; rewritten by Havoc Pennington
Developer(s) Tollef Fog Heen / freedesktop.org
Initial release2000;24 years ago (2000) or earlier
Stable release
0.29.2 / March 20, 2017;7 years ago (2017-03-20)
Repository gitlab.freedesktop.org/pkg-config/pkg-config
Written in C
Operating system Unix-like
Type Programming tool
License GNU GPL
Website www.freedesktop.org/wiki/Software/pkg-config/

pkg-config is 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.

Contents

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. [1] Later, it was rewritten in C leveraging GLib. [2]

Database

To enable use of the tool, a referenced library must have a corresponding .pc 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 .pc 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 .pc 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 Cflags entry defines an option that the C preprocessor uses to locate the library's header files in /usr/local/include/libpng12. The Libs entry defines options that define the location of library binaries, /usr/local/lib, and identify which library binary files to link.

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

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

$ gcc-otesttest.c$(pkg-config--libs--cflagslibpng)

Alternative implementations

Notable variants of pkg-config:

Related Research Articles

<span class="mw-page-title-main">Executable and Linkable Format</span> Standard file format for executables, object code, shared libraries, and core dumps.

In computing, the Executable and Linkable Format is a common standard file format for executable files, object code, shared libraries, and core dumps. First published in the specification for the application binary interface (ABI) of the Unix operating system version named System V Release 4 (SVR4), and later in the Tool Interface Standard, it was quickly accepted among different vendors of Unix systems. In 1999, it was chosen as the standard binary file format for Unix and Unix-like systems on x86 processors by the 86open project.

<span class="mw-page-title-main">Package manager</span> Software tools for handling software packages

A package manager or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer in a consistent manner.

In software development, Make is a command-line interface software tool that performs actions ordered by configured dependencies as defined in a configuration file called a makefile. It is commonly used for build automation to build executable code from source code. But, not limited to building, Make can perform any operation available via the operating system shell.

The Filesystem Hierarchy Standard (FHS) is a reference describing the conventions used for the layout of Unix-like systems. It has been made popular by its use in Linux distributions, but it is used by other Unix-like systems as well. It is maintained by the Linux Foundation. The latest version is 3.0, released on 3 June 2015.

<span class="mw-page-title-main">Portage (software)</span> Gentoo package management system

Portage is a package management system originally created for and used by Gentoo Linux and also by ChromeOS, Calculate, and Funtoo Linux among others. Portage is based on the concept of ports collections. Gentoo is sometimes referred to as a meta-distribution due to the extreme flexibility of Portage, which makes it operating-system-independent. The Gentoo/Alt project was concerned with using Portage to manage other operating systems, such as BSDs, macOS and Solaris. The most notable of these implementations is the Gentoo/FreeBSD project.

freedesktop.org (fd.o), formerly X Desktop Group (XDG), is a project to work on interoperability and shared base technology for free-software desktop environments for the X Window System (X11) and Wayland on Linux and other Unix-like operating systems. Although freedesktop.org produces specifications for interoperability, it is not a formal standards body.

<span class="mw-page-title-main">Arch Linux</span> Rolling release distribution of Linux

Arch Linux is an independently developed Linux distribution designed with a rolling-release model. The default Arch Linux installation is intentionally minimal, and is configured by the user during installation so they may add only what they require. Arch is the basis for a multitude of other distributions, such as Manjaro, EndeavourOS, and Parabola.

file (command) Standard Unix program

The file command is a standard program of Unix and Unix-like operating systems for recognizing the type of data contained in a computer file.

gtkmm is the official C++ interface for the popular GUI library GTK. gtkmm is free software distributed under the GNU Lesser General Public License (LGPL).

In computing, rpath designates the run-time search path hard-coded in an executable file or library. Dynamic linking loaders use the rpath to find required libraries.

Ports collections are the sets of makefiles and patches provided by the BSD-based operating systems, FreeBSD, NetBSD, and OpenBSD, as a simple method of installing software or creating binary packages. They are usually the base of a package management system, with ports handling package creation and additional tools managing package removal, upgrade, and other tasks. In addition to the BSDs, a few Linux distributions have implemented similar infrastructure, including Gentoo's Portage, Arch's Arch Build System (ABS), CRUX's Ports and Void Linux's Templates.

In computing, a shebang is the character sequence #!, consisting of the characters number sign and exclamation mark, at the beginning of a script. It is also called sharp-exclamation, sha-bang, hashbang, pound-bang, or hash-pling.

The FreeBSD Ports collection is a package management system for the FreeBSD operating system. Ports in the collection vary with contributed software. There were 38,487 ports available in February 2020 and 36,504 in September 2024. It has also been adopted by NetBSD as the basis of its pkgsrc system.

In computing, a hidden folder or hidden file is a folder or file which filesystem utilities do not display by default when showing a directory listing. They are commonly used for storing user preferences or preserving the state of a utility and are frequently created implicitly by using various utilities. They are not a security mechanism because access is not restricted – usually the intent is simply to not "clutter" the display of the contents of a directory listing with files the user did not directly create.

The tsort program is a command line utility on Unix and Unix-like platforms, that performs a topological sort on its input. As of 2017, it is part of the POSIX.1 standard.

configure script Shell script for generating build configuration files on a Unix-like environment

When installing a package on a Unix or Unix-like environment, a configure script is a shell script that generates build configuration files for a codebase to facilitate cross-platform support. It generates files tailoring for the host system – the environment on which the codebase is built and run.

<span class="mw-page-title-main">Vala (programming language)</span> Programming language

Vala is an object-oriented programming language with a self-hosting compiler that generates C code and uses the GObject system.

dconf Low-level configuration system for GNOME

dconf is a low-level configuration system and settings management tool. Its main purpose is to provide a back end to GSettings on platforms that don't already have configuration storage systems. It depends on GLib. It is part of GNOME as of version 3, and is a replacement for GConf.

<span class="mw-page-title-main">Meson (software)</span> Build automation tool

Meson is a software build automation tool for building a codebase. Meson adopts a convention over configuration approach to minimize the data required to configure the most common operations. Meson is free and open-source software under the Apache License 2.0.

References

  1. Havoc Pennington (4 June 2000). "Re: the *-config scripts" . Retrieved 2020-01-22.
  2. Havoc Pennington (23 July 2000). "pkg-config" . Retrieved 2020-01-22.
  3. 1 2 3 4 Found on spread of pkgconf but not spread of pkg-config on repology
  4. 1 2 3 4 https://lists.archlinux.org/pipermail/arch-dev-public/2018-May/029252.html Replacing pkg-config with pkgconf] on arch-dev-public@lists.archlinux.org