pkg-config - Unix, Linux Command

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...]


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:



program: program.c
        cc program.c ‘pkg-config --cflags --libs gnomeui‘






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").













  $ pkg-config --variable=prefix glib-2.0
  /usr/

  $ pkg-config --print-errors --define-variable=prefix=/foo \
               --variable=prefix glib-2.0
  /foo






Rather than using the version-test options, you can simply give a version
constraint after each package name, for example:

  $ pkg-config --exists ’glib-2.0 >= 1.3.4 libxml = 1.8.3’




























In 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.






The macro PKG_CHECK_MODULES can be used in configure.ac to
check whether modules exist. A typical usage would be:

 PKG_CHECK_MODULES([MYSTUFF], [gtk+-2.0 >= 1.3.5 libxml = 1.8.4])


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


PKG_PROG_PKG_CONFIG([MIN-VERSION]) 

Defines the PKG_CONFIG variable to the best pkg-config available,
useful if you need pkg-config but don’t 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






Here is an example file:

# This is a comment
prefix=/home/hp/unst   # this defines a variable
exec_prefix=${prefix}  # defining another variable in terms of the first
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: GObject                            # human-readable name
Description: Object/type system for GLib # human-readable description
Version: 1.3.1
URL: http://www.gtk.org
Requires: glib-2.0 = 1.3.1
Conflicts: foobar <= 4.5
Libs: -L${libdir} -lgobject-1.3
Libs.private: -lm
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib/include


Name: GObject                            # human-readable name
Description: Object/type system for GLib # human-readable description
Version: 1.3.1
URL: http://www.gtk.org
Requires: glib-2.0 = 1.3.1
Conflicts: foobar <= 4.5
Libs: -L${libdir} -lgobject-1.3
Libs.private: -lm
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib/include




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 "${foo}"; you can escape
literal "${" as "$${".










pkg-config was written by James Henstridge, rewritten by Martijn
van Beers, and rewritten again by Havoc Pennington. Tim Janik, Owen
Taylor, and Raja Harinath submitted suggestions and some code.
gnome-config was written by Miguel de Icaza, Raja Harinath and
various hackers in the GNOME team.  It was inspired by Owen Taylor’s
gtk-config program.




pkg-config does not handle mixing of parameters with and without
= well.  Stick with one.