#cargo-build #build-script #build-time #cargo-toml #system #build-dependencies #order

build pkg-config

A library to run the pkg-config system tool at build time in order to be used in Cargo build scripts

43 releases

Uses old Rust 2015

0.3.30 Feb 14, 2024
0.3.28 Dec 20, 2023
0.3.27 May 3, 2023
0.3.26 Oct 26, 2022
0.1.0 Nov 27, 2014

#1 in Build Utils

Download history 776132/week @ 2023-12-25 1193239/week @ 2024-01-01 1436304/week @ 2024-01-08 1478477/week @ 2024-01-15 1498734/week @ 2024-01-22 1530446/week @ 2024-01-29 1538736/week @ 2024-02-05 1571003/week @ 2024-02-12 1599209/week @ 2024-02-19 1682031/week @ 2024-02-26 1680062/week @ 2024-03-04 1645216/week @ 2024-03-11 1655245/week @ 2024-03-18 1616487/week @ 2024-03-25 1674317/week @ 2024-04-01 1133057/week @ 2024-04-08

6,184,436 downloads per month
Used in 17,940 crates (748 directly)


846 lines


Build Status Rust


A simple library meant to be used as a build dependency with Cargo packages in order to use the system pkg-config tool (if available) to determine where a library is located.

You can use this crate directly to probe for specific libraries, or use system-deps to declare all your pkg-config dependencies in Cargo.toml.

This library requires Rust 1.30+.


Find the system library named foo, with minimum version 1.2.3:

extern crate pkg_config;

fn main() {

Find the system library named foo, with no version requirement (not recommended):

extern crate pkg_config;

fn main() {

External configuration via target-scoped environment variables

In cross-compilation context, it is useful to manage separately PKG_CONFIG_PATH and a few other variables for the host and the target platform.


Each of these variables can also be supplied with certain prefixes and suffixes, in the following prioritized order:

  1. <var>_<target> - for example, PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  2. <var>_<target_with_underscores> - for example, PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  3. <build-kind>_<var> - for example, HOST_PKG_CONFIG_PATH or TARGET_PKG_CONFIG_PATH
  4. <var> - a plain PKG_CONFIG_PATH

This crate will allow pkg-config to be used in cross-compilation if PKG_CONFIG_SYSROOT_DIR or PKG_CONFIG is set. You can set PKG_CONFIG_ALLOW_CROSS=1 to bypass the compatibility check, but please note that enabling use of pkg-config in cross-compilation without appropriate sysroot and search paths set is likely to break builds.

Some Rust sys crates support building vendored libraries from source, which may be a work around for lack of cross-compilation support in pkg-config.


This project is licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in pkg-config-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps