pkg-config — Unix, Linux Command
SYNOPSIS
pkg-config [—modversion] [—help] [—print-errors] [—silence-errors] [—cflags] [—libs] [—libs-only-L] [—libs-only-l] [—cflags-only-I] [—variable=VARIABLENAME] [—define-variable=VARIABLENAME=VARIABLEVALUE] [—uninstalled] [—exists] [—atleast-version=VERSION] [—exact-version=VERSION] [—max-version=VERSION] [LIBRARIES. ]
DESCRIPTION
The pkg-config program is used to retrieve information about installed libraries in the system. It is typically used to compile and link against one or more libraries. Here is a typical usage scenario in a Makefile:
pkg-config retrieves information about packages from special metadata files. These files are named after the package, with the extension .pc. By default, pkg-config looks in the directory prefix/lib/pkgconfig for these files; it will also look in the colon-separated (on Windows, semicolon-separated) list of directories specified by the PKG_CONFIG_PATH environment variable.
The package name specified on the pkg-config command line is defined to be the name of the metadata file, minus the .pc extension. If a library can install multiple versions simultaneously, it must give each version its own name (for example, GTK 1.2 might have the package name «gtk+» while GTK 2.0 has «gtk+-2.0»).
OPTIONS
The following options are supported:
Tag | Description |
---|---|
—modversion | |
Requests that the version information of the libraries specified on the command line be displayed. If pkg-config can find all the libraries on the command line, each librarys version string is printed to stdout, one version per line. In this case pkg-config exits successfully. If one or more libraries is unknown, pkg-config exits with a nonzero code, and the contents of stdout are undefined. | |
—help | |
Displays a help message and terminates. |
—atleast-version=VERSION
—exact-version=VERSION
—max-version=VERSION These options test whether the package or list of packages on the command line are known to pkg-config, and optionally whether the version number of a package meets certain contraints. If all packages exist and meet the specified version constraints, pkg-config exits successfully. Otherwise it exits unsuccessfully.
Rather than using the version-test options, you can simply give a version constraint after each package name, for example: Remember to use —print-errors if you want error messages.
—msvc-syntax This option is available only on Windows. It causes pkg-config to output -l and -L flags in the form recognized by the Microsoft Visual C++ command-line compiler, cl. Specifically, instead of -Lx:/some/path it prints /libpath:x/some/path, and instead of -lfoo it prints foo.lib. Note that the —libs output consists of flags for the linker, and should be placed on the cl command line after a /link switch. —dont-define-prefix This option is available only on Windows. It prevents pkg-config from automatically trying to override the value of the variable «prefix» in each .pc file. —prefix-variable=PREFIX Also this option is available only on Windows. It sets the name of the variable that pkg-config automatically sets as described above. —static Output libraries suitable for static linking. That means including any private libraries in the output. This relies on proper tagging in the .pc files, else a too large number of libraries will ordinarily be output.ENVIRONMENT VARIABLES
Tag | Description | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PKG_CONFIG_PATH | |||||||||||||||||||||||||||
A colon-separated (on Windows, semicolon-separated) list of directories to search for .pc files. The default directory will always be searched after searching the path; the default is libdir/pkgconfig:datadir/pkgconfig where libdir is the libdir where pkg-config and datadir is the datadir where pkg-config was installed. | |||||||||||||||||||||||||||
PKG_CONFIG_DEBUG_SPEW | |||||||||||||||||||||||||||
If set, causes pkg-config to print all kinds of debugging information and report all errors. | |||||||||||||||||||||||||||
PKG_CONFIG_TOP_BUILD_DIR | |||||||||||||||||||||||||||
A value to set for the magic variable pc_top_builddir which may appear in .pc files. If the environment variable is not set, the default value $(top_builddir) will be used. This variable should refer to the top builddir of the Makefile where the compile/link flags reported by pkg-config will be used. This only matters when compiling/linking against a package that hasnt yet been installed. | |||||||||||||||||||||||||||
PKG_CONFIG_DISABLE_UNINSTALLED | |||||||||||||||||||||||||||
Normally if you request the package «foo» and the package «foo-uninstalled» exists, pkg-config will prefer the «-uninstalled» variant. This allows compilation/linking against uninstalled packages. If this environment variable is set, it disables said behavior. | |||||||||||||||||||||||||||
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS | |||||||||||||||||||||||||||
Dont strip -I/usr/include out of cflags. | |||||||||||||||||||||||||||
PKG_CONFIG_ALLOW_SYSTEM_LIBS | |||||||||||||||||||||||||||
Dont strip -L/usr/lib out of libs | |||||||||||||||||||||||||||
PKG_CONFIG_LIBDIR | |||||||||||||||||||||||||||
Replaces the default pkg-config search directory. WINDOWS SPECIALITIESIn addition to the PKG_CONFIG_PATH environment variable, the Registry keys HKEY_CURRENT_USER\Software\pkgconfig\PKG_CONFIG_PATH and HKEY_LOCAL_MACHINE\Software\pkgconfig\PKG_CONFIG_PATH can be used to specify directories to search for .pc files. Each (string) value in these keys is treated as a directory where to look for .pc files. AUTOCONF MACROSThe macro PKG_CHECK_MODULES can be used in configure.ac to check whether modules exist. A typical usage would be: This would result in MYSTUFF_LIBS and MYSTUFF_CFLAGS substitution variables, set to the libs and cflags for the given module list. If a module is missing or has the wrong version, by default configure will abort with a message. To replace the default action, specify an ACTION-IF-NOT-FOUND. PKG_CHECK_MODULES will not print any error messages if you specify your own ACTION-IF-NOT-FOUND. However, it will set the variable MYSTUFF_PKG_ERRORS, which you can use to display what went wrong. Note that if there is a possibility the first call to PKG_CHECK_MODULES might not happen, you should be sure to include an explicit call to PKG_PROG_PKG_CONFIG in your configure.ac Defines the PKG_CONFIG variable to the best pkg-config available, useful if you need pkg-config but dont want to use PKG_CHECK_MODULES. PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) Check to see whether a particular set of modules exists. Similar to PKG_CHECK_MODULES(), but does not set variables or print errors. Similar to PKG_CHECK_MODULES, make sure that the first instance of this or PKG_CHECK_MODULES is called, or make sure to call PKG_CHECK_EXISTS manually METADATA FILE SYNTAXHere is an example file: You would normally generate the file using configure, of course, so that the prefix, etc. are set to the proper values. Files have two kinds of line: keyword lines start with a keyword plus a colon, and variable definitions start with an alphanumeric string plus an equals sign. Keywords are defined in advance and have special meaning to pkg-config; variables do not, you can have any variables that you wish (however, users may expect to retrieve the usual directory name variables). Note that variable references are written «$
|