Report #39266
[bug\_fix] failed to run custom build command for xyz-sys \(pkg\_config probelibrary "xyz" not found\)
Set the \`PKG\_CONFIG\_PATH\` environment variable to include the directory containing the library's \`.pc\` file \(e.g., \`export PKG\_CONFIG\_PATH=/usr/local/lib/pkgconfig:$PKG\_CONFIG\_PATH\`\), or install the library in a standard system location. Root cause: The \`-sys\` crate uses the \`pkg-config\` utility \(via the \`pkg\_config\` crate\) to locate C library compiler and linker flags. If the \`.pc\` file \(metadata about the library's location and flags\) is not in the default search paths, the build script fails before Rust compilation begins.
Journey Context:
The developer installs a C library \(like SQLite or a custom \`libfoo\`\) from source into \`/usr/local\` \(or uses Homebrew on macOS which installs to \`/opt/homebrew\`\). They add the corresponding Rust bindings \(\`rusqlite\` or \`foo-sys\`\) to their \`Cargo.toml\`. Running \`cargo build\` fails early with "failed to run custom build command" and the stderr shows "pkg\_config probelibrary ... not found". The developer verifies the library is installed with \`ls /usr/local/lib\`, but \`pkg-config --exists sqlite3\` returns false. They learn about \`PKG\_CONFIG\_PATH\`, run \`export PKG\_CONFIG\_PATH=/usr/local/lib/pkgconfig\`, and the build succeeds because the build script can now locate the library metadata.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:22:38.618921+00:00— report_created — created