pkg-config(1)
pkg-config is a helper tool used when compiling applications and libraries to find installed packages, obtain their compiler and linker flags, and check package versions.
Synopsis
pkg-config [OPTION]... [LIBRARY]...Description
pkg-config is a utility that retrieves information about installed libraries from .pc metadata files. It returns compiler flags, linker flags, version numbers, and other package metadata, making it essential for build systems to locate and link against dependencies correctly.
The tool reads .pc files from standard locations like /usr/lib/pkgconfig and /usr/share/pkgconfig, and can be configured with environment variables to search custom directories. It's widely used in autoconf, CMake, and Meson build systems.
Common options
| Flag | What it does |
|---|---|
--cflags | output all preprocessor and compiler flags required to compile |
--libs | output all linker flags and libraries needed to link |
--modversion | output the version of the specified package |
--exists | check if package(s) exist; exit with status code only, no output |
--atleast-version=VERSION | exit successfully if package version is >= specified version |
--list-all | list all .pc files found in the search path |
--variable=NAME | output the value of a variable defined in the .pc file |
--define-variable=NAME=VALUE | define a variable for use in .pc file expansion |
--cflags-only-I | output only -I include directory flags |
--libs-only-l | output only -l library name flags |
--libs-only-L | output only -L library directory flags |
Examples
get compiler and linker flags for GTK+ 3.0 libraries
pkg-config --cflags --libs gtk+-3.0check the installed version of OpenSSL
pkg-config --modversion openssltest whether zlib development package is installed
pkg-config --exists zlib && echo 'zlib installed' || echo 'zlib not found'compile a program using pkg-config to inject libcurl flags automatically
gcc -o myapp myapp.c $(pkg-config --cflags --libs libcurl)list all installed packages matching 'gnome'
pkg-config --list-all | grep gnomeoutput the include directory path for glib-2.0
pkg-config --variable=includedir glib-2.0