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] [--uninstalled] [--exists] [--atleast-version=VERSION] [--exact-
13       version=VERSION] [--max-version=VERSION] [LIBRARIES...]
14

DESCRIPTION

16       The  pkg-config program is used to retrieve information about installed
17       libraries in the system.  It is typically  used  to  compile  and  link
18       against  one  or more libraries.  Here is a typical usage scenario in a
19       Makefile:
20
21       program: program.c
22            cc program.c `pkg-config --cflags --libs gnomeui`
23
24       pkg-config retrieves information about packages from  special  metadata
25       files. These files are named after the package, with the extension .pc.
26       By default, pkg-config looks in the directory prefix/lib/pkgconfig  for
27       these  files;  it  will  also  look in the colon-separated (on Windows,
28       semicolon-separated) list of  directories  specified  by  the  PKG_CON‐
29       FIG_PATH environment variable.
30
31
32       The package name specified on the pkg-config command line is defined to
33       be the name of the metadata file, minus the .pc extension. If a library
34       can install multiple versions simultaneously, it must give each version
35       its own name (for example, GTK 1.2 might have the package  name  "gtk+"
36       while GTK 2.0 has "gtk+-2.0").
37
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
54       --print-errors
55              If  one  or  more  of  the modules on the command line, or their
56              dependencies, are not found, or if an error occurs in parsing  a
57              .pc  file,  then  this  option  will cause errors explaining the
58              problem  to  be  printed.  With  "predicate"  options  such   as
59              "--exists"  pkg-config  runs  silently  by default, because it's
60              usually used in scripts that want to control what's output. This
61              option  can  be  used  alone  (to  just print errors encountered
62              locating modules on the command line) or with other options. The
63              PKG_CONFIG_DEBUG_SPEW   environment   variable   overrides  this
64              option.
65
66
67       --silence-errors
68              If one or more of the modules on  the  command  line,  or  their
69              dependencies,  are not found, or if an error occurs in parsing a
70              a .pc file, then this option will  keep  errors  explaining  the
71              problem  from  being  printed.  With "predicate" options such as
72              "--exists" pkg-config runs silently  by  default,  because  it's
73              usually  used  in scripts that want to control what's output. So
74              this option is only useful with options such  as  "--cflags"  or
75              "--modversion"  that  print  errors  by  default.  The  PKG_CON‐
76              FIG_DEBUG_SPEW environment variable overrides this option.
77
78
79       --errors-to-stdout
80              If printing errors, print them to stdout rather than the default
81              stderr
82
83
84       The following options are used to compile and link programs:
85
86       --cflags
87              This  prints pre-processor and compile flags required to compile
88              the packages on the command line, including flags for all  their
89              dependencies. Flags are "compressed" so that each identical flag
90              appears only once. pkg-config exits with a nonzero  code  if  it
91              can't  find metadata for one or more of the packages on the com‐
92              mand line.
93
94       --libs This option is identical to "--cflags", only it prints the  link
95              flags. As with "--cflags", duplicate flags are merged (maintain‐
96              ing proper ordering), and flags for dependencies are included in
97              the output.
98
99       --libs-only-L
100              This  prints the -L/-R part of "--libs". That is, it defines the
101              library search path but doesn't specify which libraries to  link
102              with.
103
104       --libs-only-l
105              This  prints the -l part of "--libs" for the libraries specified
106              on the command line. Note that the union of "--libs-only-l"  and
107              "--libs-only-L"  may be smaller than "--libs", due to flags such
108              as -rdynamic.
109
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  .pc  files. Most packages define the variable "prefix", for
121              example, so you can say:
122                $ pkg-config --print-errors --define-variable=prefix=/foo \
123                             --variable=prefix glib-2.0
124                /foo
125
126
127       --uninstalled
128              Normally if you request the package "foo" and the package  "foo-
129              uninstalled"  exists,  pkg-config will prefer the "-uninstalled"
130              variant. This  allows  compilation/linking  against  uninstalled
131              packages.  If you specify the "--uninstalled" option, pkg-config
132              will return successfully  if  any  "-uninstalled"  packages  are
133              being   used,   and  return  failure  (false)  otherwise.   (The
134              "PKG_CONFIG_DISABLE_UNINSTALLED" environment variable keeps pkg-
135              config  from  implicitly choosing "-uninstalled" packages, so if
136              that variable is set, they will only have been used if you  pass
137              a name like "foo-uninstalled" on the command line explicitly.)
138
139
140       --exists
141
142       --atleast-version=VERSION
143
144       --exact-version=VERSION
145
146       --max-version=VERSION
147              These  options  test  whether the package or list of packages on
148              the command line are known to pkg-config, and optionally whether
149              the  version  number  of a package meets certain contraints.  If
150              all packages exist and meet the specified  version  constraints,
151              pkg-config  exits  successfully.  Otherwise  it exits unsuccess‐
152              fully.
153
154              Rather than using the version-test options, you can simply  give
155              a version constraint after each package name, for example:
156                $ pkg-config --exists 'glib-2.0 >= 1.3.4 libxml = 1.8.3'
157              Remember to use --print-errors if you want error messages.
158
159
160       --msvc-syntax
161              This  option  is available only on Windows. It causes pkg-config
162              to output -l and -L flags in the form recognized by  the  Micro‐
163              soft Visual C++ command-line compiler, cl. Specifically, instead
164              of -Lx:/some/path it prints /libpath:x/some/path, and instead of
165              -lfoo it prints foo.lib. Note that the --libs output consists of
166              flags for the linker, and should be placed  on  the  cl  command
167              line after a /link switch.
168
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
176       --prefix-variable=PREFIX
177              Also  this option is available only on Windows. It sets the name
178              of the variable that pkg-config automatically sets as  described
179              above.
180
181
182       --static
183              Output  libraries  suitable  for  static  linking.   That  means
184              including any private libraries in the output.  This  relies  on
185              proper  tagging  in  the  .pc  files, else a too large number of
186              libraries will ordinarily be output.
187
188

ENVIRONMENT VARIABLES

190       PKG_CONFIG_PATH
191              A colon-separated  (on  Windows,  semicolon-separated)  list  of
192              directories to search for .pc files.  The default directory will
193              always be searched after searching the path; the default is lib‐
194              dir/pkgconfig:datadir/pkgconfig where libdir is the libdir where
195              pkg-config and datadir  is  the  datadir  where  pkg-config  was
196              installed.
197
198
199       PKG_CONFIG_DEBUG_SPEW
200              If set, causes pkg-config to print all kinds of debugging infor‐
201              mation and report all errors.
202
203
204       PKG_CONFIG_TOP_BUILD_DIR
205              A value to set for the magic variable pc_top_builddir which  may
206              appear in .pc files. If the environment variable is not set, the
207              default value '$(top_builddir)'  will  be  used.  This  variable
208              should  refer to the top builddir of the Makefile where the com‐
209              pile/link flags reported by pkg-config will be used.  This  only
210              matters when compiling/linking against a package that hasn't yet
211              been installed.
212
213
214       PKG_CONFIG_DISABLE_UNINSTALLED
215              Normally if you request the package "foo" and the package  "foo-
216              uninstalled"  exists,  pkg-config will prefer the "-uninstalled"
217              variant. This  allows  compilation/linking  against  uninstalled
218              packages.  If this environment variable is set, it disables said
219              behavior.
220
221
222       PKG_CONFIG_ALLOW_SYSTEM_CFLAGS
223              Don't strip -I/usr/include out of cflags.
224
225
226       PKG_CONFIG_ALLOW_SYSTEM_LIBS
227              Don't strip -L/usr/lib out of libs
228
229
230       PKG_CONFIG_LIBDIR
231              Replaces the default pkg-config search directory.
232
233

WINDOWS SPECIALITIES

235       If a .pc file is found in a directory that matches  the  usual  conven‐
236       tions  (i.e., ends with \lib\pkgconfig), the prefix for that package is
237       assumed to be the grandparent of  the  directory  where  the  file  was
238       found, and the prefix variable is overridden for that file accordingly.
239
240       In  addition  to the PKG_CONFIG_PATH environment variable, the Registry
241       keys      HKEY_CURRENT_USER\Software\pkgconfig\PKG_CONFIG_PATH      and
242       HKEY_LOCAL_MACHINE\Software\pkgconfig\PKG_CONFIG_PATH  can  be  used to
243       specify directories to search for .pc files.  Each  (string)  value  in
244       these keys is treated as a directory where to look for .pc files.
245
246

AUTOCONF MACROS

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

METADATA FILE SYNTAX

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

AUTHOR

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

BUGS

387       pkg-config  does  not  handle  mixing  of parameters with and without =
388       well.  Stick with one.
389
390
391
392                                                                 pkg-config(1)
Impressum