为什么 pkg-config --cflags openssl 在 RHEL 6.8 上不返回任何内容?

bgo*_*odr 4 rhel openssl pkg-config

我在 RHEL 6.8 Linux 机器上运行。我正在寻求从源 tarballs/git-repos/whatefer 构建各种包,而无需更改系统配置(在 root 或 sudo 下)。

我在 RHEL 6.8 机器上运行:

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

openssl-devel 已安装:

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
Run Code Online (Sandbox Code Playgroud)

所以我希望这个命令返回一些输出,这样当我从使用 pkg-config 的源构建包时,他们会找到他们需要的 CFLAGS 的值:

bash-4.1$ pkg-config --cflags openssl
Run Code Online (Sandbox Code Playgroud)

但它只返回一个换行符。为什么?

进一步调试:

显示正在使用的文件:

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'
Run Code Online (Sandbox Code Playgroud)

显示它应该读取的文件:

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
Run Code Online (Sandbox Code Playgroud)

扩大grep:

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$ 
Run Code Online (Sandbox Code Playgroud)

嗯,那Removing -I/usr/include from cflags for openssl在那里做什么?

此外,Cflags还定义了变量。这是一个错误吗?应该cflags改为吗?

另外,我已经下载并构建了我自己的pkg-config0.29.2 版,它提供了相同的行为。所以我怀疑openssl.pc文件中有错误,但我不确定。

即便如此,什么是修复比出口的硬编码值等CFLAGS,并LDFLAGS调用各种包之前,为了./configure脚本?

rud*_*ier 8

看起来像是pkg-config去重复标志并且还跳过了“默认”路径,比如 /usr/include。

看,

$ 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
Run Code Online (Sandbox Code Playgroud)

这些默认目录是在 pkg-config 的构建时设置的,请参阅源代码中的 README.md:

./configure \
     --prefix=/opt/pkgconf \
     --with-system-libdir=/lib:/usr/lib \
     --with-system-includedir=/usr/include
Run Code Online (Sandbox Code Playgroud)

您可以在运行时通过环境变量禁用该行为:

$ PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --cflags  /tmp/x.pc
-I/usr/include
Run Code Online (Sandbox Code Playgroud)

或覆盖内置默认值:

$ PKG_CONFIG_SYSTEM_INCLUDE_PATH="/whatever" pkg-config --cflags  /tmp/x.pc
-I/usr/include
Run Code Online (Sandbox Code Playgroud)

最近的 pkg-config 也有命令行选项--keep-system-cflags--keep-system-libs

  • @bgoodr 自述文件在这里 https://github.com/pkgconf/pkgconf。提到的环境变量记录在手册页 `man pkg-config` 中 (2认同)
  • @bgoodr 刚刚注意到 `pkg-config` 和 `pkgconfig` 是两种不同的实现。它们应该可以互换,但可能有不同的错误和文档。我猜他们分叉 pkg-config 是因为它对 glib 有一个令人讨厌的依赖,所以很难在异国情调的系统上构建。 (2认同)