Differences between revisions 6 and 11 (spanning 5 versions)
Revision 6 as of 2013-05-29 07:08:51
Size: 2045
Editor: hgiger
Comment:
Revision 11 as of 2020-09-10 09:22:14
Size: 2000
Editor: bonaccos
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from PKGConfigVariable #rev 2020-09-10 bonaccos

Line 3: Line 5:
= Using pkg-config to set variables =
When compiling software from source you might need to set variables such as {{{$CFLAGS}}} or {{{$LDFLAGS}}}. Here the {{{pkg-config}}} command comes handy. Nevertheless, {{{pkg-config}}} only works with libraries supporting {{{pkg-config}}}, meaning that there is a {{{/pkgconfig}}} sub-directory in the library dir with a corresponding {{{*.pc}}} file. If that is the case you can easily set these variables by typing (tcsh):

== Using pkg-config to set variables ==

When compiling software from source you might need to set variables such as `CFLAGS` or `LDFLAGS`. Here the `pkg-config` command comes handy. Nevertheless, `pkg-config` only works with libraries supporting `pkg-config`, meaning that there is a '''/pkgconfig''' sub-directory in the library directory with a corresponding `*.pc` file. If that is the case you can easily set these variables by typing (bash):
Line 7: Line 11:
> setenv CFLAGS "`pkg-config --cflags PACKAGE-NAME`" export CFLAGS="`pkg-config --cflags PACKAGE-NAME`"
Line 12: Line 16:
> setenv LDLAGS "`pkg-config --libs PACKAGE-NAME`" export LDLAGS="`pkg-config --libs PACKAGE-NAME`"
Line 14: Line 18:
where {{{PACKAGE-NAME}}} is the package you need. However, by default {{{pkg-config}}} looks for {{{*.pc}}} files contained in {{{/usr/lib/pkgconfig}}} only. If you need {{{pkg-config}}} to search another path as well you may set the {{{$PKG_CONFIG_PATH}}} variable accordingly. This variable must contain paths leading to a directory containing {{{*.pc}}} files. Very often a package comes with a {{{pkg-config}}} directory containing the corresponding {{{*.pc}}} files. You may set multiple paths in the {{{$PKG_CONFIG_PATH}}} variable using {{{:}}} as separator. Here is an example setting two additional paths:
where '''PACKAGE-NAME''' is the package you need. However, by default `pkg-config` looks for '''*.pc''' files in system defined paths only. If you need `pkg-config` to search another path as well you may set the `PKG_CONFIG_PATH` variable accordingly. This variable contain paths leading to a directory containing `*.pc'` files. A package might come with a `pkg-config` directory containing the corresponding `*.pc` files. You may set multiple paths in the `PKG_CONFIG_PATH` variable using colon (`:`) as separator.

Here is an example setting two additional paths:
Line 17: Line 24:
> setenv PKG_CONFIG_PATH "path1-to-*.pc-files:path2-to-*.pc-files" export PKG_CONFIG_PATH="path1-to-*.pc-files:path2-to-*.pc-files"
Line 20: Line 27:
It is important to note that the {{{--libs}}} option sometimes only returns the link time directory, omitting the run time directory. Therefore, you might have to correct the {{{LDFLAGS}}} variable accordingly. It is important to note that the `--libs` option sometimes only returns the link time directory, omitting the run time directory. Therefore, you might have to correct the `LDFLAGS` variable accordingly.
Line 22: Line 29:
Remark: Paths contained in {{{$PKG_CONFIG_PATH}}} are preferred over the default path by {{{pkg-config}}}. This means if a corresponding {{{*.pc}}} file is found in the {{{$PKG_CONFIG_PATH}}} directories, a {{{*.pc}}} with the same name in {{{/usr/lib/pkgconfig}}} will not be considered. Remark: Paths contained in `PKG_CONFIG_PATH` are preferred over the default path by `pkg-config`. This means if a corresponding `*.pc` file is found in the `PKG_CONFIG_PATH` directories, a `*.pc` with the same name for instance in `/usr/lib/pkgconfig` will not be considered.
Line 24: Line 31:
Here is an example (again in tcsh): Here is an example:
Line 27: Line 34:
> setenv CFLAGS `"pkg-config --cflags gtk+-2.0"` export CFLAGS="`pkg-config --cflags gtk+-2.0`"
Line 29: Line 36:
type {{{man pkg-config}}} for further information.
Line 31: Line 37:
More details can be found in the [[https://manpages.debian.org/buster/pkgconf/pkg-config.1.en.html|pkg-config(1) manpage]].
Line 33: Line 40:
[[CategoryLXCL]] [[CategoryLXSW]]

PKG-CONFIG

Using pkg-config to set variables

When compiling software from source you might need to set variables such as CFLAGS or LDFLAGS. Here the pkg-config command comes handy. Nevertheless, pkg-config only works with libraries supporting pkg-config, meaning that there is a /pkgconfig sub-directory in the library directory with a corresponding *.pc file. If that is the case you can easily set these variables by typing (bash):

export CFLAGS="`pkg-config --cflags PACKAGE-NAME`"

and

export LDLAGS="`pkg-config --libs PACKAGE-NAME`"

where PACKAGE-NAME is the package you need. However, by default pkg-config looks for *.pc files in system defined paths only. If you need pkg-config to search another path as well you may set the PKG_CONFIG_PATH variable accordingly. This variable contain paths leading to a directory containing *.pc' files. A package might come with a pkg-config directory containing the corresponding *.pc files. You may set multiple paths in the PKG_CONFIG_PATH variable using colon (:) as separator.

Here is an example setting two additional paths:

export PKG_CONFIG_PATH="path1-to-*.pc-files:path2-to-*.pc-files"

It is important to note that the --libs option sometimes only returns the link time directory, omitting the run time directory. Therefore, you might have to correct the LDFLAGS variable accordingly.

Remark: Paths contained in PKG_CONFIG_PATH are preferred over the default path by pkg-config. This means if a corresponding *.pc file is found in the PKG_CONFIG_PATH directories, a *.pc with the same name for instance in /usr/lib/pkgconfig will not be considered.

Here is an example:

export CFLAGS="`pkg-config --cflags gtk+-2.0`"

More details can be found in the pkg-config(1) manpage.


CategoryLXSW

Workstations/Linux/Applications/PKGConfig (last edited 2020-09-10 09:22:14 by bonaccos)