Why is pkg-config –cflags openssl returning nothing on RHEL 6.8

opensslpkg-configrhel

I'm running on a RHEL 6.8 Linux machine. I am seeking to build various packages from source tarballs/git-repos/whatefer without changing the system configuration (under root or sudo).

I'm running on a RHEL 6.8 machine:

bash-4.1$ cat /etc/issue
Red Hat Enterprise Linux Workstation release 6.8 (Santiago)
Kernel \r on an \m

openssl-devel is installed:

bash-4.1$ rpm -q -a | grep openssl
openssl-1.0.1e-48.el6.i686
openssl098e-0.9.8e-20.el6_7.1.x86_64
openssl098e-0.9.8e-20.el6_7.1.i686
openssl-devel-1.0.1e-48.el6.i686
openssl-1.0.1e-48.el6.x86_64
openssl-devel-1.0.1e-48.el6.x86_64

So I expect that this command to return some output, so that when I build packages from source that use pkg-config, they will find the value of CFLAGS they need:

bash-4.1$ pkg-config --cflags openssl

But it returns just a newline. Why?

Further debugging:

Show what file it is using:

bash-4.1$ pkg-config --debug --list-all 2>&1 | grep 'Will find package.*openssl'
Will find package 'openssl' in file '/usr/lib64/pkgconfig/openssl.pc'

Show the file it should be reading:

bash-4.1$ cat /usr/lib64/pkgconfig/openssl.pc
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib64
includedir=${prefix}/include

Name: OpenSSL
Description: Secure Sockets Layer and cryptography libraries and tools
Version: 1.0.1e
Requires: 
Libs: -L${libdir} -lssl -lcrypto
Libs.private: -Wl,-z,relro -ldl -lz -L/usr/lib -lgssapi_krb5 -lkrb5 -lcom_err -lk5crypto -lresolv
Cflags: -I${includedir} -I/usr/include

Widening the grep out:

bash-4.1$ pkg-config --debug --list-all 2>&1 | grep 'openssl'
File 'openssl.pc' appears to be a .pc file
Will find package 'openssl' in file '/usr/lib64/pkgconfig/openssl.pc'
Looking for package 'openssl'
Looking for package 'openssl-uninstalled'
Reading 'openssl' from file '/usr/lib64/pkgconfig/openssl.pc'
Parsing package file '/usr/lib64/pkgconfig/openssl.pc'
Unknown keyword 'Libs.private' in '/usr/lib64/pkgconfig/openssl.pc'
Removing -I/usr/include from cflags for openssl
Removing -I/usr/include from cflags for openssl
Removing -L /usr/lib64 from libs for openssl
Adding 'openssl' to list of known packages, returning as package 'openssl'
openssl                     OpenSSL - Secure Sockets Layer and cryptography libraries and tools
bash-4.1$ 

Hmmm what is that Removing -I/usr/include from cflags for openssl doing there?

Also, the Cflags variable is defined. Is that a bug? Should it be cflags instead?

Also, I've downloaded and built my own pkg-config, version 0.29.2, and it gives the same behavior. So I'm suspecting a bug in the openssl.pc file, but am not sure.

Even so, what is the fix other than exporting hardcoded values of CFLAGS and LDFLAGS just prior to calling the various packages ./configure scripts?

Best Answer

It seems like pkg-config de-duplicates flags and also skips "default" paths, like /usr/include.

See,

$ printf "Name: whatever\nVersion: 1\nDescription: bla\nCflags: -I/usr/include" > /tmp/x.pc
$ pkg-config --cflags  /tmp/x.pc

$ printf "Name: whatever\nVersion: 1\nDescription: bla\nCflags: -I/usr/includeX" > /tmp/y.pc
$ pkg-config --cflags  /tmp/y.pc
-I/usr/includeX

These default directories are set at pkg-config's build time, see README.md in the sources:

./configure \
     --prefix=/opt/pkgconf \
     --with-system-libdir=/lib:/usr/lib \
     --with-system-includedir=/usr/include

You can disable that behavior at runtime via environment variable:

$ PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --cflags  /tmp/x.pc
-I/usr/include

or override the built-in default:

$ PKG_CONFIG_SYSTEM_INCLUDE_PATH="/whatever" pkg-config --cflags  /tmp/x.pc
-I/usr/include

Recent pkg-config also has commandline options --keep-system-cflags and --keep-system-libs

Related Question