Skip to content
Latchkey

pkg-config: Usage, Options & Common CI Errors

pkg-config reports the -I and -l flags a library needs from its .pc file.

pkg-config is the glue that lets builds discover library flags without hardcoding paths. The defining CI error - "Package X was not found in the pkg-config search path" - is almost always a missing -dev package or an unset PKG_CONFIG_PATH.

What it does

pkg-config reads .pc metadata files installed alongside libraries and prints the compiler and linker flags needed to use them. Build systems call it (often via $(pkg-config --cflags --libs foo)) so they do not hardcode include and library paths.

Common usage

Terminal
pkg-config --cflags --libs openssl
gcc main.c \$(pkg-config --cflags --libs glib-2.0) -o app
pkg-config --exists libfoo && echo present
pkg-config --modversion zlib
export PKG_CONFIG_PATH=/opt/lib/pkgconfig:\$PKG_CONFIG_PATH

Options

FlagWhat it does
--cflagsPrint include flags (-I, -D)
--libsPrint link flags (-L, -l)
--existsExit 0 if the package is found
--modversionPrint the installed version
PKG_CONFIG_PATHExtra dirs to search for .pc files

Common errors in CI

"Package foo was not found in the pkg-config search path. Perhaps you should add the directory containing ‘foo.pc’ to the PKG_CONFIG_PATH" - install the library’s -dev/-devel package (the .pc ships there) or export PKG_CONFIG_PATH to its location. For cross builds the host .pc files are wrong; use a target sysroot and PKG_CONFIG_LIBDIR. "pkg-config: command not found" on slim images - install pkg-config (or pkgconf). A bad --modversion comparison can also abort configure scripts.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →