pkgconf now replacing pkg-config in RHEL 8

Latest response

I work in an organization that relies heavily on in-house developed software, and we've been based on RHEL for longer than I've been here. I write software mainly targeted to RHEL 6 and 7, and I often use Fedora for development and my own personal computers.

Recently I've run into a strange situation with setting up libraries after installation with pkg-config. Noteably that it doesn't include /usr/local/lib/pkgconfig in its default search path for .pc files, and that you can't override this behavior by setting PKG_CONFIG_PATH in the normal way. After much head scratching and wasted time, I discovered that as of F26, the standard pkg-config utility was replaced by another utility called pkgconf, with /usr/bin/pkg-config replaced with a symlink. This would be fine if pkgconf were compatible with the real pkg-config, a utility that much of the linux C developer world uses and depends on, but it's not.

Now, I've found that this mistake has been propagated to RHEL 8.

Now I'm left in a position where in-house written and 3rd-party libraries installed to the correct, canonical location for locally-compiled software (/usr/local/lib) cannot be found by this fake pkg-config utility, even when PKG_CONFIG_PATH is correctly set to /usr/local/lib/pkgconfig, due to what is either a defect or a designed incompatibility in this new utility.

[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

This seems like a pretty fundamental problem for RHEL 8 shops that operate with a lot of internally-developed software, and/or 3rd-party software that's compiled from source. I'm having no luck in finding anything online about what developers working in Fedora or RHEL 8 generally do about it however, except waste time in confusion as I have recently. Should I just have install scripts try to detect that the target platform is Fedora or RHEL 8 using pkgconf, and put .pc files in /usr/share/pkgconfig instead? (I hope it's clear that this is a terrible, kludgy solution.)

It seems like the switch to this "pkgconf" utility is the answer to a question that essentially no one was asking, and as an incompatible replacement to a core utility that the linux development community depends on, it is causing more problems than it's solving.

Responses

Legacy pkgconfig in RHEL 7 and older was never configured to support /usr/local search paths. This behavior did not change in RHEL 8.

The behavior you're asking for works perfectly fine in Red Hat Enterprise Linux 8, at least as verified with the UBI8 base container:

~> podman run --pull=always --rm -it registry.access.redhat.com/ubi8/ubi
Trying to pull registry.access.redhat.com/ubi8/ubi...
Getting image source signatures
Copying blob 47db82df7f3f skipped: already exists
Copying blob 77c58f19bd6e [--------------------------------------] 0.0b / 0.0b
Copying config a1f8c96997 done
Writing manifest to image destination
Storing signatures
[root@979c95543c4e /]# cd ~
[root@979c95543c4e ~]# dnf -y install /usr/bin/pkg-config
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Red Hat Universal Base Image 8 (RPMs) - BaseOS  904 kB/s | 768 kB     00:00
Red Hat Universal Base Image 8 (RPMs) - AppStre 6.3 MB/s | 3.9 MB     00:00
Red Hat Universal Base Image 8 (RPMs) - CodeRea  63 kB/s |  11 kB     00:00
Dependencies resolved.
================================================================================
 Package                 Arch        Version            Repository         Size
================================================================================
Installing:
 pkgconf-pkg-config      x86_64      1.4.2-1.el8        ubi-8-baseos       15 k
Installing dependencies:
 libpkgconf              x86_64      1.4.2-1.el8        ubi-8-baseos       35 k
 pkgconf                 x86_64      1.4.2-1.el8        ubi-8-baseos       38 k
 pkgconf-m4              noarch      1.4.2-1.el8        ubi-8-baseos       17 k

Transaction Summary
================================================================================
Install  4 Packages

Total download size: 105 k
Installed size: 144 k
Downloading Packages:
(1/4): pkgconf-m4-1.4.2-1.el8.noarch.rpm        228 kB/s |  17 kB     00:00
(2/4): pkgconf-pkg-config-1.4.2-1.el8.x86_64.rp 743 kB/s |  15 kB     00:00
(3/4): pkgconf-1.4.2-1.el8.x86_64.rpm           381 kB/s |  38 kB     00:00
(4/4): libpkgconf-1.4.2-1.el8.x86_64.rpm        330 kB/s |  35 kB     00:00
--------------------------------------------------------------------------------
Total                                           766 kB/s | 105 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : pkgconf-m4-1.4.2-1.el8.noarch                          1/4
  Installing       : libpkgconf-1.4.2-1.el8.x86_64                          2/4
  Installing       : pkgconf-1.4.2-1.el8.x86_64                             3/4
  Installing       : pkgconf-pkg-config-1.4.2-1.el8.x86_64                  4/4
  Running scriptlet: pkgconf-pkg-config-1.4.2-1.el8.x86_64                  4/4
  Verifying        : libpkgconf-1.4.2-1.el8.x86_64                          1/4
  Verifying        : pkgconf-m4-1.4.2-1.el8.noarch                          2/4
  Verifying        : pkgconf-1.4.2-1.el8.x86_64                             3/4
  Verifying        : pkgconf-pkg-config-1.4.2-1.el8.x86_64                  4/4
Installed products updated.

Installed:
  libpkgconf-1.4.2-1.el8.x86_64      pkgconf-1.4.2-1.el8.x86_64
  pkgconf-m4-1.4.2-1.el8.noarch      pkgconf-pkg-config-1.4.2-1.el8.x86_64

Complete!
[root@979c95543c4e ~]# vi test.pc
[root@979c95543c4e ~]# cat test.pc
Name: test
Description: test library
Version: 0
Libs: -ltest
Cflags: -I/usr/include
[root@979c95543c4e ~]# PKG_CONFIG_PATH=/root pkg-config --libs test
-ltest

Most likely, your .pc file is malformed in some way. You can check this by running pkgconf --validate /path/to/package.pc to see what is wrong so you can fix it.