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_SYSROOT_DIR
231              Modify -I and -L to use the directories located in  target  sys‐
232              root.   this  option is usefull when crosscompiling package that
233              use pkg-config to determine CFLAGS anf LDFLAGS. -I  and  -L  are
234              modified  to  point  to  the  new system root. this means that a
235              -I/usr/include/libfoo will become -I/var/target/usr/include/lib‐
236              foo  with  a  PKG_CONFIG_SYSROOT_DIR  equal to /var/target (same
237              rule apply to -L)
238
239
240       PKG_CONFIG_LIBDIR
241              Replaces the default pkg-config search directory.
242
243

WINDOWS SPECIALITIES

245       If a .pc file is found in a directory that matches  the  usual  conven‐
246       tions  (i.e., ends with \lib\pkgconfig), the prefix for that package is
247       assumed to be the grandparent of  the  directory  where  the  file  was
248       found, and the prefix variable is overridden for that file accordingly.
249
250       In  addition  to the PKG_CONFIG_PATH environment variable, the Registry
251       keys      HKEY_CURRENT_USER\Software\pkgconfig\PKG_CONFIG_PATH      and
252       HKEY_LOCAL_MACHINE\Software\pkgconfig\PKG_CONFIG_PATH  can  be  used to
253       specify directories to search for .pc files.  Each  (string)  value  in
254       these keys is treated as a directory where to look for .pc files.
255
256

AUTOCONF MACROS

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

METADATA FILE SYNTAX

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

AUTHOR

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

BUGS

397       pkg-config  does  not  handle  mixing  of parameters with and without =
398       well.  Stick with one.
399
400
401
402                                                                 pkg-config(1)
Impressum