Skip to content
Latchkey

pkg-config --cflags --libs: Find Compile Flags

pkg-config --cflags --libs <name> prints the include and link flags a library needs, read from its installed .pc file.

pkg-config is how build systems discover where a library's headers and libs live. In CI, missing .pc files or an unset PKG_CONFIG_PATH are a frequent cause of configure failures.

What it does

pkg-config reads a package's .pc metadata file and prints the flags to use it: --cflags for include paths and defines, --libs for linker flags. --exists checks availability, and --modversion reports the version, all without hard-coding paths.

Common usage

Terminal
pkg-config --cflags --libs openssl
gcc app.c $(pkg-config --cflags --libs libcurl) -o app
pkg-config --exists 'zlib >= 1.2' && echo present
PKG_CONFIG_PATH=/opt/lib/pkgconfig pkg-config --libs foo

Options

Flag / envWhat it does
--cflags <name>Print preprocessor and compile flags
--libs <name>Print linker flags
--exists <name>Exit 0 if the package is available
--modversion <name>Print the installed version
--list-allList every known package
PKG_CONFIG_PATH (env)Extra directories to search for .pc files

In CI

Install the development packages (e.g. libssl-dev) so the .pc files exist; runtime-only packages ship no .pc. If a library is in a non-standard prefix, export PKG_CONFIG_PATH to its lib/pkgconfig directory. On minimal images, install pkg-config itself before any autotools/meson configure that calls it.

Common errors in CI

"pkg-config: command not found" means pkg-config is not installed; add the pkg-config package. "Package foo was not found in the pkg-config search path" means the .pc file is missing (install the -dev package) or PKG_CONFIG_PATH does not include its directory. "No package 'foo' found" during ./configure or meson setup is the same root cause surfacing through PKG_CHECK_MODULES.

Related guides

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