pkg-config主要的作用是提供編譯和連接到軟件庫的信息的。
如,典型的用法:
[heidong@HEIDONGVM bin]$ pkg-config --cflags --libs libevent
-I/usr/local/include -L/usr/local/lib -levent
將顯示包含頭文件和連接的信息。
那麼pkg-config是如何獲取得這些信息的呢?
pkg-config 是從xxx.pc的文件裏面取的軟件包的信息,如上面的例子,libevent.pc
[heidong@HEIDONGVM bin]$ cat /usr/local/lib/pkgconfig/libevent.pc
#libevent pkg-config source file
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: libevent
Description: libevent is an asynchronous notification event loop library
Version: 2.0.17-stable
Requires:
Conflicts:
Libs: -L${libdir} -levent
Libs.private: -lrt
Cflags: -I${includedir}
可見,pkg-config裏面主要包含了包含頭文件,連接庫的信息。在本例子中,Requires就空的,如果非空,cfalgs, libs將添加相應的依賴項。
那麼pkg-config是從哪裏搜索這些文件的呢?
首先pkg-config會從自己標準的搜索目錄(如/usr/lib/pkgconfig/)和PKG_CONFIG_PATH環境變量目錄尋找。
如果尋找不到,會輸出這樣的信息:
[heidong@HEIDONGVM bin]$ pkg-config --libs qt
Package qt was not found in the pkg-config search path.
Perhaps you should add the directory containing `qt.pc'
to the PKG_CONFIG_PATH environment variable
No package 'qt' found
可見pkg-config對減輕編程人員的工作負荷有一定的幫助。