[CMake] pkgconfig and cross compiling

Alan W. Irwin irwin at beluga.phys.uvic.ca
Tue Nov 4 19:32:08 EST 2008


On 2008-11-04 20:57+0100 Alexander Neundorf wrote:

> On Tuesday 04 November 2008, Alan W. Irwin wrote:
> ...
>> I don't get the behaviour you describe for my version of pkg-config
>> (0.22-1).
>>
>> For that version of pkg-config, if I point PKG_CONFIG_LIBDIR to a directory
>> then if the required *.pc file is not in that directory, then it gives an
>> error message and quits, i.e., it finds nothing else regardless of how
>> PKG_CONFIG_PATH is set. As you have stated that is the ideal behaviour for
>> cross-compilation.
>>
>> I suspect the problem is you are using a really old version of pkg-config.
>> There is a bug report at https://bugs.freedesktop.org/show_bug.cgi?id=3093
>> that describes the incorrect behaviour of PKG_CONFIG_LIBDIR that you see on
>> your system.  That bug was fixed as of version pkg-config 0.18 (released in
>> June 2005).
>>
>> So install a recent version of pkg-config, and I think your troubles with
>> PKG_CONFIG_LIBDIR will be over.
>
> Hmm. Directly copied from my terminal:
> hammer:~$ echo $PKG_CONFIG_PATH
> /usr/local/lib/pkgconfig:/usr/lib/pkgconfig
> hammer:~$ export PKG_CONFIG_LIBDIR=/tmp
> hammer:~$ strace pkg-config alsa --variable=includedir 2> pkgconfig.log
> /usr/include
> hammer:~$ grep alsa.pc pkgconfig.log
> open("/usr/lib/pkgconfig/alsa.pc", O_RDONLY) = 3
> hammer:~$ pkg-config --version
> 0.21
> hammer:~$
>
> (there are no pc-files in /tmp)

Thanks for that test.  I confirm your version of pkg-config is not the source
of the problem. In fact, it turns out we got different results because I
didn't test the case of putting /usr/lib/pkgconfig on PKG_CONFIG_PATH like
you did.  If I do that, I confirm your result, but why do you need to
inject a native path into pkg-config like that when cross-compiling?  Isn't
that bound to lead to trouble?

The situation is as follows: PKG_CONFIG_PATH is searched before
PKG_CONFIG_LIBDIR for the desired *.pc file.  (The man page doesn't say
which is searched first, but my tests reveal that is the order at least for
the present version of pkg-config.) Cross-compiling users should avoid using
native paths in PKG_CONFIG_PATH and PKG_CONFIG_LIBDIR. Furthermore,
cross-compiling users should always specify PKG_CONFIG_LIBDIR (with or
without PKG_CONFIG_PATH) since use of PKG_CONFIG_LIBDIR supresses appending
default native paths to whatever is specified in PKG_CONFIG_PATH and
PKG_CONFIG_LIBDIR.

In sum, for cross-compilation purposes you should always use
PKG_CONFIG_LIBDIR (with or without PKG_CONFIG_PATH) and make sure there are
no native paths in it (or in PKG_CONFIG_PATH).  If you follow those rules
you should get a good cross-compilation result, otherwise not.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list