Chris Robison
Chris Robison

Reputation: 169

How to get pkg-config to use PKG_CONFIG_PATH?

I've written a small library and I'm trying to set it up to be usable with pkg-config, for those in my organization who might need to make use of it later. So my installer places a .pc file in /usr/local/lib/pkgconfig, and I've recently discovered that for some reason this isn't in the default list of directories that pkg-config scans for its pc files, despite /usr/local being the canonical prefix for locally-compiled software. So, I need to add /usr/local/lib/pkgconfig to PKG_CONFIG_PATH.

However, I'm finding that despite claims in the man page, pkg-config's own error message and everywhere online, pkg-config doesn't actually look at PKG_CONFIG_PATH. The error message tells me to add /usr/local/lib/pkgconfig (which contains the .pc file I'm looking for) to PKG_CONFIG_PATH, when I've clearly already done that.

[chris@delphinus-a pkgconfig]$ pwd
/usr/local/lib/pkgconfig
[chris@delphinus-a pkgconfig]$ ls
libexample.pc
[chris@delphinus-a pkgconfig]$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
[chris@delphinus-a pkgconfig]$ echo $PKG_CONFIG_PATH
/usr/local/lib/pkgconfig
[chris@delphinus-a pkgconfig]$ pkg-config --cflags libexample
Package libexample was not found in the pkg-config search path.
Perhaps you should add the directory containing `libexample.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libexample', required by 'virtual:world', not found
[chris@delphinus-a pkgconfig]$ echo $PKG_CONFIG_PATH
/usr/local/lib/pkgconfig
[chris@delphinus-a pkgconfig]$ pkg-config --variable pc_path pkg-config
/usr/lib64/pkgconfig:/usr/share/pkgconfig
[chris@delphinus-a pkgconfig]$ pkg-config --version
1.6.3

The contents of libexample.pc:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include

Name: libexample
Description: example library.

Libs: -L${libdir}  -lpthread -ltimeutil -lczmq -lzmq
Cflags: -I${includedir}

So, if PKG_CONFIG_PATH is indeed the environment variable I need to set, how to I get pkg-config to actually use it? Or what else am I missing here? This is in Fedora 31, FWIW.

Upvotes: 7

Views: 24304

Answers (2)

polynomial_donut
polynomial_donut

Reputation: 303

Besides what @Ruslan wrote: I found that you have to export PKG_CONFIG_LIBDIR=<your custom library directory> as well (I didn't try unsetting PKG_CONFIG_DIR, but I suppose it's also necessary).

So in your case export PKG_CONFIG_LIBDIR=/usr/local/lib besides the other export. That fixed it for me. This is pretty annoying; I don't understand why autotools misdirect to PKG_CONFIG_DIR and omit the other variable. They probably forgot to update the error output.

Upvotes: 0

Ruslan
Ruslan

Reputation: 19100

Apparently (judging by the very large version number), you're using some other implementation of pkg-config: namely, from this page I gather that it's something called pkgconf and is intended to somehow replace the FDO pkg-config program.

To succeed with PKG_CONFIG_PATH, I suppose, you should install a real pkg-config from FDO, whose version should be in the range of 0.29.x.

Upvotes: 2

Related Questions