1pkg-config(1)               General Commands Manual              pkg-config(1)
2
3
4

NAME

6       pkg-config - Return metainformation about installed libraries
7

SYNOPSIS

9       pkg-config  [--modversion] [--help] [--print-errors] [--silence-errors]
10       [--cflags] [--libs] [--libs-only-L]  [--libs-only-l]  [--cflags-only-I]
11       [--variable=VARIABLENAME]     [--define-variable=VARIABLENAME=VARIABLE‐
12       VALUE] [--print-variables] [--uninstalled]  [--exists]  [--atleast-ver‐
13       sion=VERSION]     [--exact-version=VERSION]     [--max-version=VERSION]
14       [--list-all]  [LIBRARIES...]    [--print-provides]   [--print-requires]
15       [--print-requires-private] [LIBRARIES...]
16

DESCRIPTION

18       The  pkg-config program is used to retrieve information about installed
19       libraries in the system.  It is typically  used  to  compile  and  link
20       against  one  or more libraries.  Here is a typical usage scenario in a
21       Makefile:
22
23       program: program.c
24            cc program.c $(pkg-config --cflags --libs gnomeui)
25
26       pkg-config retrieves information about packages from  special  metadata
27       files.  These  files  are named after the package, and has a .pc exten‐
28       sion.  On most systems, pkg-config looks in and
29        for these files.  It will additionally look in the colon-separated (on
30       Windows,  semicolon-separated)  list  of  directories  specified by the
31       PKG_CONFIG_PATH environment variable.
32
33       The package name specified on the pkg-config command line is defined to
34       be the name of the metadata file, minus the .pc extension. If a library
35       can install multiple versions simultaneously, it must give each version
36       its  own  name (for example, GTK 1.2 might have the package name "gtk+"
37       while GTK 2.0 has "gtk+-2.0").
38

OPTIONS

40       The following options are supported:
41
42       --modversion
43              Requests that the version information of the libraries specified
44              on  the  command  line be displayed.  If pkg-config can find all
45              the libraries on the command line, each library's version string
46              is  printed  to  stdout, one version per line. In this case pkg-
47              config exits successfully. If one or more libraries is  unknown,
48              pkg-config exits with a nonzero code, and the contents of stdout
49              are undefined.
50
51       --help Displays a help message and terminates.
52
53       --print-errors
54              If one or more of the modules on  the  command  line,  or  their
55              dependencies,  are not found, or if an error occurs in parsing a
56              .pc file, then this option  will  cause  errors  explaining  the
57              problem   to  be  printed.  With  "predicate"  options  such  as
58              "--exists" pkg-config runs silently  by  default,  because  it's
59              usually used in scripts that want to control what's output. This
60              option can be used  alone  (to  just  print  errors  encountered
61              locating modules on the command line) or with other options. The
62              PKG_CONFIG_DEBUG_SPEW  environment   variable   overrides   this
63              option.
64
65       --silence-errors
66              If  one  or  more  of  the modules on the command line, or their
67              dependencies, are not found, or if an error occurs in parsing  a
68              a  .pc  file,  then  this option will keep errors explaining the
69              problem from being printed. With  "predicate"  options  such  as
70              "--exists"  pkg-config  runs  silently  by default, because it's
71              usually used in scripts that want to control what's  output.  So
72              this  option  is  only useful with options such as "--cflags" or
73              "--modversion"  that  print  errors  by  default.  The  PKG_CON‐
74              FIG_DEBUG_SPEW environment variable overrides this option.
75
76       --errors-to-stdout
77              If printing errors, print them to stdout rather than the default
78              stderr
79
80
81       The following options are used to compile and link programs:
82
83       --cflags
84              This prints pre-processor and compile flags required to  compile
85              the  packages on the command line, including flags for all their
86              dependencies. Flags are "compressed" so that each identical flag
87              appears  only  once.  pkg-config exits with a nonzero code if it
88              can't find metadata for one or more of the packages on the  com‐
89              mand line.
90
91       --cflags-only-I
92              This  prints  the -I part of "--cflags". That is, it defines the
93              header search path but doesn't specify anything else.
94
95       --libs This option is identical to "--cflags", only it prints the  link
96              flags. As with "--cflags", duplicate flags are merged (maintain‐
97              ing proper ordering), and flags for dependencies are included in
98              the output.
99
100       --libs-only-L
101              This  prints the -L/-R part of "--libs". That is, it defines the
102              library search path but doesn't specify which libraries to  link
103              with.
104
105       --libs-only-l
106              This  prints the -l part of "--libs" for the libraries specified
107              on the command line. Note that the union of "--libs-only-l"  and
108              "--libs-only-L"  may be smaller than "--libs", due to flags such
109              as -rdynamic.
110
111       --variable=VARIABLENAME
112              This returns the value of a variable defined in a package's  .pc
113              file.  Most  packages define the variable "prefix", for example,
114              so you can say:
115                $ pkg-config --variable=prefix glib-2.0
116                /usr/
117
118       --define-variable=VARIABLENAME=VARIABLEVALUE
119              This sets a global value for a variable, overriding the value in
120              any files. Most packages define the variable "prefix", for exam‐
121              ple, so you can say:
122                $ pkg-config --print-errors --define-variable=prefix=/foo \
123                             --variable=prefix glib-2.0
124                /foo
125
126       --print-variables
127              Returns a list of all variables defined in the package.
128
129
130       --uninstalled
131              Normally if you request the package "foo" and the package  "foo-
132              uninstalled"  exists,  pkg-config will prefer the "-uninstalled"
133              variant. This  allows  compilation/linking  against  uninstalled
134              packages.  If you specify the "--uninstalled" option, pkg-config
135              will return successfully  if  any  "-uninstalled"  packages  are
136              being used, and return failure (false) otherwise.  (The PKG_CON‐
137              FIG_DISABLE_UNINSTALLED environment  variable  keeps  pkg-config
138              from  implicitly  choosing  "-uninstalled"  packages, so if that
139              variable is set, they will only have been used  if  you  pass  a
140              name like "foo-uninstalled" on the command line explicitly.)
141
142       --exists
143
144       --atleast-version=VERSION
145
146       --exact-version=VERSION
147
148       --max-version=VERSION
149              These  options  test  whether the package or list of packages on
150              the command line are known to pkg-config, and optionally whether
151              the  version  number  of a package meets certain contraints.  If
152              all packages exist and meet the specified  version  constraints,
153              pkg-config  exits  successfully.  Otherwise  it exits unsuccess‐
154              fully.
155
156              Rather than using the version-test options, you can simply  give
157              a version constraint after each package name, for example:
158                $ pkg-config --exists 'glib-2.0 >= 1.3.4 libxml = 1.8.3'
159              Remember to use --print-errors if you want error messages.
160
161       --msvc-syntax
162              This  option  is available only on Windows. It causes pkg-config
163              to output -l and -L flags in the form recognized by  the  Micro‐
164              soft Visual C++ command-line compiler, cl. Specifically, instead
165              of it prints  /libpath:x/some/path,  and  instead  of  -lfoo  it
166              prints  foo.lib.  Note  that the --libs output consists of flags
167              for the linker, and should be placed  on  the  cl  command  line
168              after a /link switch.
169
170       --dont-define-prefix
171              This option is available only on Windows. It prevents pkg-config
172              from automatically trying to override the value of the  variable
173              "prefix" in each .pc file.
174
175       --prefix-variable=PREFIX
176              Also  this option is available only on Windows. It sets the name
177              of the variable that pkg-config automatically sets as  described
178              above.
179
180       --static
181              Output  libraries  suitable  for  static  linking.   That  means
182              including any private libraries in the output.  This  relies  on
183              proper  tagging  in  the  .pc  files, else a too large number of
184              libraries will ordinarily be output.
185
186       --list-all
187              List all modules found in the pkg-config path.
188
189       -I "--print-provides"
190              List all modules the given packages provides.
191
192       --print-requires
193              List all modules the given packages requires.
194
195       --print-requires-private
196              List all modules the given packages requires for static  linking
197              (see --static).
198

ENVIRONMENT VARIABLES

200       PKG_CONFIG_PATH
201              A  colon-separated  (on  Windows,  semicolon-separated)  list of
202              directories to search for .pc files.  The default directory will
203              always  be  searched  after  searching  the path; the default is
204              libdir/pkgconfig:datadir/pkgconfig where libdir  is  the  libdir
205              for pkg-config and datadir is the datadir for pkg-config when it
206              was installed.
207
208       PKG_CONFIG_DEBUG_SPEW
209              If set, causes pkg-config to print all kinds of debugging infor‐
210              mation and report all errors.
211
212       PKG_CONFIG_TOP_BUILD_DIR
213              A  value to set for the magic variable pc_top_builddir which may
214              appear in .pc files. If the environment variable is not set, the
215              default  value  '$(top_builddir)'  will  be  used. This variable
216              should refer to the top builddir of the Makefile where the  com‐
217              pile/link  flags reported by pkg-config will be used.  This only
218              matters when compiling/linking against a package that hasn't yet
219              been installed.
220
221       PKG_CONFIG_DISABLE_UNINSTALLED
222              Normally  if you request the package "foo" and the package "foo-
223              uninstalled" exists, pkg-config will prefer  the  "-uninstalled"
224              variant.  This  allows  compilation/linking  against uninstalled
225              packages.  If this environment variable is set, it disables said
226              behavior.
227
228       PKG_CONFIG_ALLOW_SYSTEM_CFLAGS
229              Don't strip -I/usr/include out of cflags.
230
231       PKG_CONFIG_ALLOW_SYSTEM_LIBS
232              Don't strip -L/usr/lib out of libs
233
234       PKG_CONFIG_SYSROOT_DIR
235              Modify  -I  and -L to use the directories located in target sys‐
236              root.  this option is useful when  crosscompiling  package  that
237              use  pkg-config  to  determine CFLAGS anf LDFLAGS. -I and -L are
238              modified to point to the new system  root.  this  means  that  a
239              -I/usr/include/libfoo will become -I/var/target/usr/include/lib‐
240              foo with a PKG_CONFIG_SYSROOT_DIR  equal  to  /var/target  (same
241              rule apply to -L)
242
243       PKG_CONFIG_LIBDIR
244              Replaces   the  default  pkg-config  search  directory,  usually
245              /usr/lib/pkgconfig
246

QUERYING PKG-CONFIG'S DEFAULTS

248       pkg-config can be used to query itself for  the  default  search  path,
249       version number and other information, for instance using:
250         $ pkg-config --variable pc_path pkg-config
251       or
252         $ pkg-config --modversion pkg-config
253

WINDOWS SPECIALITIES

255       If  a  .pc  file is found in a directory that matches the usual conven‐
256       tions (i.e., ends with \lib\pkgconfig or \share\pkgconfig), the  prefix
257       for  that  package  is  assumed  to be the grandparent of the directory
258       where the file was found, and the prefix  variable  is  overridden  for
259       that file accordingly.
260
261       If the value of a variable in a .pc file begins with the original, non-
262       overridden, value of the prefix variable, then the overridden value  of
263       prefix is used instead.
264

AUTOCONF MACROS

266       PKG_CHECK_MODULES(VARIABLE-PREFIX,  MODULES [,ACTION-IF-FOUND [,ACTION-
267       IF-NOT-FOUND]])
268
269              The macro PKG_CHECK_MODULES can be used in configure.ac to check
270              whether modules exist. A typical usage would be:
271               PKG_CHECK_MODULES([MYSTUFF], [gtk+-2.0 >= 1.3.5 libxml = 1.8.4])
272
273              This  would  result in MYSTUFF_LIBS and MYSTUFF_CFLAGS substitu‐
274              tion variables, set to the libs and cflags for the given  module
275              list.   If  a  module  is  missing  or has the wrong version, by
276              default configure will abort with  a  message.  To  replace  the
277              default      action,     specify     an     ACTION-IF-NOT-FOUND.
278              PKG_CHECK_MODULES will not print any error messages if you spec‐
279              ify  your  own  ACTION-IF-NOT-FOUND.   However,  it will set the
280              variable MYSTUFF_PKG_ERRORS, which you can use to  display  what
281              went wrong.
282
283              Note   that  if  there  is  a  possibility  the  first  call  to
284              PKG_CHECK_MODULES might  not  happen,  you  should  be  sure  to
285              include  an explicit call to PKG_PROG_PKG_CONFIG in your config‐
286              ure.ac.
287
288       PKG_PROG_PKG_CONFIG([MIN-VERSION])
289
290              Defines the PKG_CONFIG variable to the  best  pkg-config  avail‐
291              able,  useful  if  you  need  pkg-config  but  don't want to use
292              PKG_CHECK_MODULES.
293
294       PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
295
296              Check to see whether a particular set of modules exists.   Simi‐
297              lar  to PKG_CHECK_MODULES(), but does not set variables or print
298              errors.
299
300              Similar to PKG_CHECK_MODULES, make sure that the first  instance
301              of  this  or  PKG_CHECK_MODULES  is called, or make sure to call
302              PKG_CHECK_EXISTS manually.
303
304

METADATA FILE SYNTAX

306       To add a library to the set of packages pkg-config knows about,  simply
307       install a .pc file. You should install this file to libdir/pkgconfig.
308
309       Here is an example file:
310       # This is a comment
311       prefix=/home/hp/unst   # this defines a variable
312       exec_prefix=${prefix}  # defining another variable in terms of the first
313       libdir=${exec_prefix}/lib
314       includedir=${prefix}/include
315
316       Name: GObject                            # human-readable name
317       Description: Object/type system for GLib # human-readable description
318       Version: 1.3.1
319       URL: http://www.gtk.org
320       Requires: glib-2.0 = 1.3.1
321       Conflicts: foobar <= 4.5
322       Libs: -L${libdir} -lgobject-1.3
323       Libs.private: -lm
324       Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib/include
325
326       You  would  normally  generate  the file using configure, of course, so
327       that the prefix, etc. are set to the proper values.
328
329       Files have two kinds of line: keyword lines start with a keyword plus a
330       colon,  and variable definitions start with an alphanumeric string plus
331       an equals sign. Keywords are defined in advance and have special  mean‐
332       ing  to  pkg-config;  variables do not, you can have any variables that
333       you wish (however, users may expect to  retrieve  the  usual  directory
334       name variables).
335
336       Note that variable references are written "${foo}"; you can escape lit‐
337       eral "${" as "$${".
338
339       Name:  This field should be a human-readable name for the package. Note
340              that it is not the name passed as an argument to pkg-config.
341
342       Description:
343              This should be a brief description of the package
344
345       URL:   An  URL where people can get more information about and download
346              the package
347
348       Version:
349              This  should  be  the  most-specific-possible  package   version
350              string.
351
352       Requires:
353              This  is a comma-separated list of packages that are required by
354              your package. Flags from dependent packages will be merged in to
355              the flags reported for your package. Optionally, you can specify
356              the version of the required package (using the operators  =,  <,
357              >,  >=,  <=);  specifying a version allows pkg-config to perform
358              extra sanity checks. You may only mention the same  package  one
359              time  on  the  Requires:  line.  If  the version of a package is
360              unspecified, any version will be used with no checking.
361
362       Requires.private:
363              A list of packages required by this package. The difference from
364              Requires  is that the packages listed under Requires.private are
365              not taken into account when a flag list is computed for  dynami‐
366              cally linked executable (i.e., when --static was not specified).
367              In the situation where each .pc file corresponds to  a  library,
368              Requires.private shall be used exclusively to specify the depen‐
369              dencies between the libraries.
370
371       Conflicts:
372              This optional line allows pkg-config to perform additional  san‐
373              ity  checks, primarily to detect broken user installations.  The
374              syntax is the same as Requires: except that  you  can  list  the
375              same  package  more than once here, for example "foobar = 1.2.3,
376              foobar = 1.2.5, foobar >= 1.3", if you have reason to do so.  If
377              a  version isn't specified, then your package conflicts with all
378              versions of the mentioned package.  If a user tries to use  your
379              package  and  a  conflicting package at the same time, then pkg-
380              config will complain.
381
382       Libs:  This line should give the link flags specific to  your  package.
383              Don't  add  any flags for required packages; pkg-config will add
384              those automatically.
385
386       Libs.private:
387              This line should list any private  libraries  in  use.   Private
388              libraries  are  libraries  which  are  not  exposed through your
389              library, but are needed in the case of static linking. This dif‐
390              fers  from Requires.private in that it references libraries that
391              do not have package files installed.
392
393       Cflags:
394              This line should list the compile flags specific to  your  pack‐
395              age.  Don't add any flags for required packages; pkg-config will
396              add those automatically.
397

AUTHOR

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

BUGS

406       pkg-config does not handle mixing of  parameters  with  and  without  =
407       well.  Stick with one.
408
409       Bugs can be reported at http://bugs.freedesktop.org/ under the pkg-con‐
410       fig component.
411
412
413
414                                                                 pkg-config(1)
Impressum