Skip to content
Latchkey

cargo build script "pkg-config ... could not be found" (system lib) in CI

A -sys crate's build script uses pkg-config to locate a system library (zlib, libpq, sqlite3, dbus) and the development package is not installed. Without the .pc metadata and headers, the build script cannot link the native library.

What this error means

cargo build fails inside a build script with "The system library X required by crate X-sys was not found" and a hint to install the -dev package or set PKG_CONFIG_PATH.

cargo
error: failed to run custom build command for `libsqlite3-sys v0.28.0`
  --- stderr
  The system library `sqlite3` required by crate `libsqlite3-sys` was not found.
  The file `sqlite3.pc` needs to be installed ... HINT: install the libsqlite3 development package.

Common causes

The library development package is not installed

A slim runner lacks the -dev/-devel package, so the headers and .pc file pkg-config needs are absent.

pkg-config cannot see the library metadata

The library is present but its .pc file is in a location not on PKG_CONFIG_PATH, so pkg-config reports it missing.

How to fix it

Install the development package

Add pkg-config and the library -dev package the build script names, before cargo runs.

Terminal
sudo apt-get update
sudo apt-get install -y pkg-config libsqlite3-dev

Point pkg-config at the metadata

If the library is installed in a non-standard prefix, expose its pkgconfig directory.

Terminal
export PKG_CONFIG_PATH=/opt/lib/pkgconfig:$PKG_CONFIG_PATH
cargo build

How to prevent it

  • Install pkg-config and required -dev libraries in a setup step.
  • Bake common system libraries into a custom runner image.
  • Prefer crates with a bundled/vendored feature when available.

Related guides

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