Size: 2045
Comment:
|
Size: 2574
Comment: mark pkg-config as command
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
#rev 2018-10-30 stroth |
|
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 dir with a corresponding '''*.pc''' file. If that is the case you can easily set these variables by typing (tcsh): |
Line 14: | Line 16: |
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 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: |
Line 20: | Line 22: |
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 24: |
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 in '''/usr/lib/pkgconfig''' will not be considered. |
Line 29: | Line 31: |
type {{{man pkg-config}}} for further information. | type '''man pkg-config''' for further information. |
Line 31: | Line 33: |
== Typical PKG_CONFIG_PATH == '''*.pc''' files are typically placed in an directory named '''pkgconfig''' . Those directories are found below '''lib''' , inside sub-directories of '''lib''' and in '''share'''. As a typical '''$PKG_CONFIG_PATH''' you can use the followign command (bash) and prepend your own paths: |
|
Line 32: | Line 36: |
{{{ $ export PKG_CONFIG_PATH=' /usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig' }}} |
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 dir with a corresponding *.pc file. If that is the case you can easily set these variables by typing (tcsh):
> setenv CFLAGS "`pkg-config --cflags PACKAGE-NAME`"
and
> setenv LDLAGS "`pkg-config --libs PACKAGE-NAME`"
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:
> setenv 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 in /usr/lib/pkgconfig will not be considered.
Here is an example (again in tcsh):
> setenv CFLAGS `"pkg-config --cflags gtk+-2.0"`
type man pkg-config for further information.
Typical PKG_CONFIG_PATH
*.pc files are typically placed in an directory named pkgconfig . Those directories are found below lib , inside sub-directories of lib and in share. As a typical $PKG_CONFIG_PATH you can use the followign command (bash) and prepend your own paths:
$ export PKG_CONFIG_PATH=' /usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig'