4

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?

1 Answer 1

9

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

6
  • Thanks! people.freedesktop.org/~dbn/pkg-config-guide.html is the guide which says "pkg-config needs to output both sets of link flags in this case to ensure that the statically linked application will find all the necessary symbols. On the other hand, it will always output all the Cflags". That documentation says nothing about deduplication, so seems like perhaps they forgot to update the docs. Upon further thought, it probably does make sense that -I/usr/include is excluded IFF the compiler has /usr/include in its default include paths.
    – bgoodr
    Commented Apr 30, 2017 at 18:40
  • Where is the README.md you referenced? I cannot find it online. I did find a README file at cgit.freedesktop.org/pkg-config/tree/README
    – bgoodr
    Commented Apr 30, 2017 at 18:42
  • 2
    @bgoodr The README is here github.com/pkgconf/pkgconf. The mentioned environment variables are documented in the man page man pkg-config
    – rudimeier
    Commented Apr 30, 2017 at 18:47
  • Understood. Must be a website bug: github.com/pkgconf/pkgconf/issues/117
    – bgoodr
    Commented May 2, 2017 at 15:07
  • 2
    @bgoodr Just noticed that pkg-config and pkgconfig are two different implementations. They should be interchangeable but may have different bugs and documentation. I guess they forked pkg-config because it has an annoying dependency on glib, so it's hard to build on exotic systems.
    – rudimeier
    Commented May 3, 2017 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .