How to get pkg-config to use PKG_CONFIG_PATH?
Asked Answered
G

2

7

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.

Guido answered 14/1, 2020 at 15:45 Comment(2)
What are the contents of the .pc file?Abrahamabrahams
Added the .pc file to the question.Guido
A
2

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.

Abrahamabrahams answered 14/1, 2020 at 16:8 Comment(2)
Yep, looks like Fedora does not provide the real pkg-config in its default repositories for some reason, only pkgconf. This may be a defect in pkgconf, or something else I don't understand about configuring it.Guido
Just for the record: maybe back then pkgconf did not honor PKG_CONFIG_PATH, but now it most definitely does. So in 2024 this answer is not correct anymore.Melly
A
0

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.

Ankylosis answered 27/3, 2023 at 23:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.