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

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

我在 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

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

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

bash-4.1$ pkg-config --cflags openssl

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

进一步调试:

显示它正在使用什么文件:

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'

显示它应该读取的文件:

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

扩大 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$ 

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

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

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

即便如此,除了在调用各种包脚本之前导出硬编码值之外CFLAGS,还有什么解决办法呢?LDFLAGS./configure

答案1

它似乎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

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

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

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

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

或覆盖内置默认值:

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

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

相关内容