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]  [--version]  [--help] [--atleast-pkgconfig-
10       version=VERSION] [--print-errors]  [--short-errors]  [--silence-errors]
11       [--errors-to-stdout]   [--debug]  [--cflags]  [--libs]  [--libs-only-L]
12       [--libs-only-l] [--cflags-only-I]  [--libs-only-other]  [--cflags-only-
13       other]  [--variable=VARIABLENAME] [--define-variable=VARIABLENAME=VARI‐
14       ABLEVALUE] [--print-variables] [--uninstalled]  [--exists]  [--atleast-
15       version=VERSION]    [--exact-version=VERSION]   [--max-version=VERSION]
16       [--list-all]  [LIBRARIES...]    [--print-provides]   [--print-requires]
17       [--print-requires-private] [LIBRARIES...]
18

DESCRIPTION

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

OPTIONS

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

ENVIRONMENT VARIABLES

229       PKG_CONFIG_PATH
230              A  colon-separated  (on  Windows,  semicolon-separated)  list of
231              directories to search for .pc files.  The default directory will
232              always  be  searched  after  searching  the path; the default is
233              libdir/pkgconfig:datadir/pkgconfig where libdir  is  the  libdir
234              for pkg-config and datadir is the datadir for pkg-config when it
235              was installed.
236
237       PKG_CONFIG_DEBUG_SPEW
238              If set, causes pkg-config to print all kinds of debugging infor‐
239              mation and report all errors.
240
241       PKG_CONFIG_TOP_BUILD_DIR
242              A  value to set for the magic variable pc_top_builddir which may
243              appear in .pc files. If the environment variable is not set, the
244              default  value  '$(top_builddir)'  will  be  used. This variable
245              should refer to the top builddir of the Makefile where the  com‐
246              pile/link  flags reported by pkg-config will be used.  This only
247              matters when compiling/linking against a package that hasn't yet
248              been installed.
249
250       PKG_CONFIG_DISABLE_UNINSTALLED
251              Normally  if you request the package "foo" and the package "foo-
252              uninstalled" exists, pkg-config will prefer  the  "-uninstalled"
253              variant.  This  allows  compilation/linking  against uninstalled
254              packages.  If this environment variable is set, it disables said
255              behavior.
256
257       PKG_CONFIG_ALLOW_SYSTEM_CFLAGS
258              Don't strip -I/usr/include out of cflags.
259
260       PKG_CONFIG_ALLOW_SYSTEM_LIBS
261              Don't strip -L/usr/lib out of libs
262
263       PKG_CONFIG_SYSROOT_DIR
264              Modify  -I  and -L to use the directories located in target sys‐
265              root.  this option is useful when cross-compiling packages  that
266              use  pkg-config  to  determine CFLAGS and LDFLAGS. -I and -L are
267              modified to point to the new system  root.  this  means  that  a
268              -I/usr/include/libfoo will become -I/var/target/usr/include/lib‐
269              foo with a PKG_CONFIG_SYSROOT_DIR  equal  to  /var/target  (same
270              rule apply to -L)
271
272       PKG_CONFIG_LIBDIR
273              Replaces   the  default  pkg-config  search  directory,  usually
274              /usr/lib/pkgconfig
275

QUERYING PKG-CONFIG'S DEFAULTS

277       pkg-config can be used to query itself for  the  default  search  path,
278       version number and other information, for instance using:
279         $ pkg-config --variable pc_path pkg-config
280       or
281         $ pkg-config --modversion pkg-config
282

WINDOWS SPECIALITIES

284       If  a  .pc  file is found in a directory that matches the usual conven‐
285       tions (i.e., ends with \lib\pkgconfig or \share\pkgconfig), the  prefix
286       for  that  package  is  assumed  to be the grandparent of the directory
287       where the file was found, and the prefix  variable  is  overridden  for
288       that file accordingly.
289
290       If the value of a variable in a .pc file begins with the original, non-
291       overridden, value of the prefix variable, then the overridden value  of
292       prefix is used instead.
293

AUTOCONF MACROS

295       PKG_CHECK_MODULES(VARIABLE-PREFIX,  MODULES [,ACTION-IF-FOUND [,ACTION-
296       IF-NOT-FOUND]])
297
298              The macro PKG_CHECK_MODULES can be used in configure.ac to check
299              whether modules exist. A typical usage would be:
300               PKG_CHECK_MODULES([MYSTUFF], [gtk+-2.0 >= 1.3.5 libxml = 1.8.4])
301
302              This  would  result in MYSTUFF_LIBS and MYSTUFF_CFLAGS substitu‐
303              tion variables, set to the libs and cflags for the given  module
304              list.   If  a  module  is  missing  or has the wrong version, by
305              default configure will abort with  a  message.  To  replace  the
306              default      action,     specify     an     ACTION-IF-NOT-FOUND.
307              PKG_CHECK_MODULES will not print any error messages if you spec‐
308              ify  your  own  ACTION-IF-NOT-FOUND.   However,  it will set the
309              variable MYSTUFF_PKG_ERRORS, which you can use to  display  what
310              went wrong.
311
312              Note   that  if  there  is  a  possibility  the  first  call  to
313              PKG_CHECK_MODULES might  not  happen,  you  should  be  sure  to
314              include  an explicit call to PKG_PROG_PKG_CONFIG in your config‐
315              ure.ac.
316
317              Also note that repeated usage of VARIABLE-PREFIX is  not  recom‐
318              mended.  After the first successful usage, subsequent calls with
319              the same VARIABLE-PREFIX will simply use the _LIBS  and  _CFLAGS
320              variables set from the previous usage without calling pkg-config
321              again.
322
323       PKG_PROG_PKG_CONFIG([MIN-VERSION])
324
325              Defines the PKG_CONFIG variable to the  best  pkg-config  avail‐
326              able,  useful  if  you  need  pkg-config  but  don't want to use
327              PKG_CHECK_MODULES.
328
329       PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
330
331              Check to see whether a particular set of modules exists.   Simi‐
332              lar  to PKG_CHECK_MODULES(), but does not set variables or print
333              errors.
334
335              Similar to PKG_CHECK_MODULES, make sure that the first  instance
336              of  this  or  PKG_CHECK_MODULES  is called, or make sure to call
337              PKG_CHECK_EXISTS manually.
338
339

METADATA FILE SYNTAX

341       To add a library to the set of packages pkg-config knows about,  simply
342       install a .pc file. You should install this file to libdir/pkgconfig.
343
344       Here is an example file:
345       # This is a comment
346       prefix=/home/hp/unst   # this defines a variable
347       exec_prefix=${prefix}  # defining another variable in terms of the first
348       libdir=${exec_prefix}/lib
349       includedir=${prefix}/include
350
351       Name: GObject                            # human-readable name
352       Description: Object/type system for GLib # human-readable description
353       Version: 1.3.1
354       URL: http://www.gtk.org
355       Requires: glib-2.0 = 1.3.1
356       Conflicts: foobar <= 4.5
357       Libs: -L${libdir} -lgobject-1.3
358       Libs.private: -lm
359       Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib/include
360
361       You  would normally generate the file using configure, so that the pre‐
362       fix, etc. are set to the proper values.  The GNU Autoconf manual recom‐
363       mends generating files like .pc files at build time rather than config‐
364       ure time, so when you build the .pc file is a matter of taste and pref‐
365       erence.
366
367       Files have two kinds of line: keyword lines start with a keyword plus a
368       colon, and variable definitions start with an alphanumeric string  plus
369       an  equals sign. Keywords are defined in advance and have special mean‐
370       ing to pkg-config; variables do not, you can have  any  variables  that
371       you  wish  (however,  users  may expect to retrieve the usual directory
372       name variables).
373
374       Note that variable references are written "${foo}"; you can escape lit‐
375       eral "${" as "$${".
376
377       Name:  This field should be a human-readable name for the package. Note
378              that it is not the name passed as an argument to pkg-config.
379
380       Description:
381              This should be a brief description of the package
382
383       URL:   An URL where people can get more information about and  download
384              the package
385
386       Version:
387              This   should  be  the  most-specific-possible  package  version
388              string.
389
390       Requires:
391              This is a comma-separated list of packages that are required  by
392              your package. Flags from dependent packages will be merged in to
393              the flags reported for your package. Optionally, you can specify
394              the  version  of the required package (using the operators =, <,
395              >, >=, <=); specifying a version allows  pkg-config  to  perform
396              extra  sanity  checks. You may only mention the same package one
397              time on the Requires: line. If  the  version  of  a  package  is
398              unspecified, any version will be used with no checking.
399
400       Requires.private:
401              A list of packages required by this package. The difference from
402              Requires is that the packages listed under Requires.private  are
403              not  taken into account when a flag list is computed for dynami‐
404              cally linked executable (i.e., when --static was not specified).
405              In  the  situation where each .pc file corresponds to a library,
406              Requires.private shall be used exclusively to specify the depen‐
407              dencies between the libraries.
408
409       Conflicts:
410              This  optional line allows pkg-config to perform additional san‐
411              ity checks, primarily to detect broken user installations.   The
412              syntax  is  the  same  as Requires: except that you can list the
413              same package more than once here, for example "foobar  =  1.2.3,
414              foobar  = 1.2.5, foobar >= 1.3", if you have reason to do so. If
415              a version isn't specified, then your package conflicts with  all
416              versions  of the mentioned package.  If a user tries to use your
417              package and a conflicting package at the same  time,  then  pkg-
418              config will complain.
419
420       Libs:  This  line  should give the link flags specific to your package.
421              Don't add any flags for required packages; pkg-config  will  add
422              those automatically.
423
424       Libs.private:
425              This  line  should  list  any private libraries in use.  Private
426              libraries are libraries  which  are  not  exposed  through  your
427              library, but are needed in the case of static linking. This dif‐
428              fers from Requires.private in that it references libraries  that
429              do not have package files installed.
430
431       Cflags:
432              This  line  should list the compile flags specific to your pack‐
433              age.  Don't add any flags for required packages; pkg-config will
434              add those automatically.
435

AUTHOR

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

BUGS

444       pkg-config  does  not  handle  mixing  of parameters with and without =
445       well.  Stick with one.
446
447       Bugs can be reported at http://bugs.freedesktop.org/ under the pkg-con‐
448       fig component.
449
450
451
452                                                                 pkg-config(1)
Impressum