為什麼 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

相關內容