Skip to content
Latchkey

CMake "Could NOT find PkgConfig" in CI

find_package(PkgConfig REQUIRED) needs the pkg-config binary on PATH. On a slim runner that binary is not installed, so CMake reports it cannot find PkgConfig and stops at configure time. Installing pkg-config fixes it.

What this error means

CMake configure fails with "Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)". It appears before any library lookups that depend on pkg-config.

CMake
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)

Common causes

pkg-config is not installed on the runner

A minimal image omits pkg-config, so the PkgConfig module cannot find its executable.

pkg-config is present but not on PATH

The binary exists in a non-standard location the runner shell does not search.

How to fix it

Install pkg-config

Add the pkg-config package with the runner OS package manager before configuring.

Terminal
# Debian/Ubuntu
sudo apt-get update && sudo apt-get install -y pkg-config
# macOS
brew install pkg-config

Point CMake at the executable

If pkg-config is installed in a custom path, tell CMake where it is.

Terminal
cmake -B build -DPKG_CONFIG_EXECUTABLE=/opt/pkg-config/bin/pkg-config

How to prevent it

  • Install pkg-config in the setup step before CMake configure.
  • Bake pkg-config into custom runner images used for C/C++ builds.
  • Keep the toolchain packages (compiler, pkg-config, ninja) provisioned together.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →