Expand description

A build dependency for Cargo libraries to find system artifacts through the pkg-config utility.

This library will shell out to pkg-config as part of build scripts and probe the system to determine how to link to a specified library. The Config structure serves as a method of configuring how pkg-config is invoked in a builder style.

A number of environment variables are available to globally configure how this crate will invoke pkg-config:

  • FOO_NO_PKG_CONFIG - if set, this will disable running pkg-config when probing for the library named foo.

  • PKG_CONFIG_ALLOW_CROSS - The pkg-config command usually doesn’t support cross-compilation, and this crate prevents it from selecting incompatible versions of libraries. Setting PKG_CONFIG_ALLOW_CROSS=1 disables this protection, which is likely to cause linking errors, unless pkg-config has been configured to use appropriate sysroot and search paths for the target platform.

There are also a number of environment variables which can configure how a library is linked to (dynamically vs statically). These variables control whether the --static flag is passed. Note that this behavior can be overridden by configuring explicitly on Config. The variables are checked in the following order:

  • FOO_STATIC - pass --static for the library foo
  • FOO_DYNAMIC - do not pass --static for the library foo
  • PKG_CONFIG_ALL_STATIC - pass --static for all libraries
  • PKG_CONFIG_ALL_DYNAMIC - do not pass --static for all libraries

After running pkg-config all appropriate Cargo metadata will be printed on stdout if the search was successful.

Example

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

fn main() {
    pkg_config::Config::new().atleast_version("1.2.3").probe("foo").unwrap();
}

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

fn main() {
    pkg_config::probe_library("foo").unwrap();
}

Configure how library foo is linked to.

fn main() {
    pkg_config::Config::new().atleast_version("1.2.3").statik(true).probe("foo").unwrap();
}

Structs

Enums

Represents all reasons pkg-config might not succeed or be run at all.

Functions

Run pkg-config to get the value of a variable from a package using --variable.
Simple shortcut for using all default options for finding a library.