LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

pkg-config

Query library compiler and linker flags

TLDR

Get compiler flags
$ pkg-config --cflags [library]
copy
Get linker flags
$ pkg-config --libs [library]
copy
Get all flags
$ pkg-config --cflags --libs [library]
copy
Check if library exists
$ pkg-config --exists [library] && echo "Found"
copy
Get library version
$ pkg-config --modversion [library]
copy
List all packages
$ pkg-config --list-all
copy

SYNOPSIS

pkg-config [options] [packages]

DESCRIPTION

pkg-config retrieves compiler and linker flags needed to build software against installed libraries. It reads metadata from .pc files that libraries install, providing the correct include paths, library paths, and link flags.Build systems like autotools, CMake, and Meson use pkg-config to locate libraries portably. The --cflags flag returns compiler flags (include paths), --libs returns linker flags, and --modversion shows the installed version. Version constraints can be checked with --atleast-version.

PARAMETERS

PACKAGES

Package names.
--cflags
Compiler flags.
--libs
Linker flags.
--exists
Check existence.
--modversion
Show version.
--list-all
List packages.
--atleast-version VERSION
Exit successfully if version is at least VERSION.
--print-errors
Show errors when package not found.

CONFIGURATION

PKG_CONFIG_PATH

Colon-separated list of additional directories to search for .pc files.
PKG_CONFIG_LIBDIR
Override the default .pc file search path entirely.

CAVEATS

Requires .pc files. PKGCONFIGPATH for custom locations.

HISTORY

pkg-config was created by James Henstridge around 2001 as part of the freedesktop.org project to simplify library compilation and linking. It is widely used in autotools, CMake, and Meson build systems.

SEE ALSO

make(1), gcc(1), pkgconf(1)

Copied to clipboard
Kai