8

I have a couple projects I maintain that are built using automake (let's call them lib1 and lib2). lib2 is dependent on lib1 as a library and I'm having some issues with the pkg-config defaults on CentOS. Ideally, I'd like users to not have to set any environment variables to get everything to install properly.

Right now, it's just assuming ${PREFIX}/lib/pkgconfig as the destination for my .pc files, but on CentOS 7, the default for ${PREFIX} is /usr/local but pkgconfig by default only looks in /usr/share/pkgconfig and /usr/lib64/pkgconfig. Therefore, lib2 can't find lib1 with pkg-config and the configure script blows up.

So, the question is, how can my make install in lib1 properly detect the directory to install the pkg-config files?

jww
  • 97,681
  • 90
  • 411
  • 885
Bill Brasky
  • 2,614
  • 2
  • 19
  • 20
  • Consider adding search directories to the [`PKG_CONFIG_PATH`](http://stackoverflow.com/questions/11303730/pkg-config-cannot-find-pc-files-although-they-are-in-the-path?rq=1) environment variable. `man pkg-config` has more details on env-vars. – Brett Hale Mar 12 '15 at 07:48
  • That works fine. However, I was looking for a solution so that common platforms (e.g. RHEL/CentOS) work with their default configurations! – Bill Brasky Mar 12 '15 at 18:16
  • So you want a solution based on `PKG_CHECK_MODULES` macro in `configure.ac`? If a directory isn't in built in to pkg-config's search path, you're going to need to set a search directory *somewhere*. – Brett Hale Mar 13 '15 at 03:15
  • The question really isn't where to search for pacakges, but where to *install* the .pc files. More like a macro to figure out where pkgconfig wants its pc files to go since ${prefix}/lib/pkgconfig seems to be wrong in this case. – Bill Brasky Mar 13 '15 at 16:08
  • `confg.site` controls where to find things, like a library directory of `lib64` on Red Hat-based systems. Fedora suffers the problem, too. Also see [config.site for vendor libs on Fedora x86_64](https://stackoverflow.com/q/46847939/608639). – jww May 14 '19 at 03:37

1 Answers1

2

From man pkg-config

PKG_INSTALLDIR(DIRECTORY)

Substitutes the variable pkgconfigdir as the location where a module should install pkg-config .pc files. By default the directory is $libdir/pkgconfig, but the default can be changed by passing DIRECTORY. The user can override through the --with-pkgconfigdir parameter.

This allows you expose the install-directory of the pkg-config file to the user (and - if your distribution patched pkg-config to use non-standard search-paths, it hopefully will pick the proper default for your system).

Example:

configure.ac:

[...]
PKG_INSTALLDIR
[...]

Makefile.am:

[...]
pkgconfig_DATA = lib1.pc
[...]

Usage

$ ./configure --prefix=/usr --with-pkgconfigdir=/usr/lib64/pkgconfig

Note

Please do not make distro-specific assumptions about where pkg-config will look for files. Always use the defaults (they are defaults for good reasons), and provide a way to override these defaults for non-standard systems.

There are a lot distributions out there, and just because in my community one is prevailing, this doesn't mean that this is true for other communities (or not going to change).

If your distro does not follow the standard that's ok, but it should be consistent; if it fails to do be consistent (e.g. pkg-config looking for files in /foo/baz, but PKG_INSTALLDIR expanding pkgconfigdir to /usr/lib/pkg-config), then you should report a bug at your distribution.

Also I think it rather weird, that your pkg-config won't search for files in /usr/local. E.g. on my Debian/sid system, it first searches /usr/local and then /usr:

$ which pkg-config
/usr/bin/pkg-config

$ strace -e trace=open pkg-config --cflags foo 2>&1  | grep /usr
open("/usr/local/lib/x86_64-linux-gnu/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/share/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
open("/usr/lib/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
open("/usr/share/pkgconfig", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
$
umläute
  • 28,885
  • 9
  • 68
  • 122