1. pkg-config --list-all
列出所有可使用的連結庫,位置在 /usr/lib/pkgconfig 及 /usr/local/lib/pkgconfig 裏面的 xxx.pc 檔,新軟體一般都會安裝 .pc 檔,沒有可以自己建立,並且設定環境變數 PKG_CONFIG_PATH 供 pkg-config 尋找 .pc 檔路徑。

2. pkg-config --cflags xxxx
取得該連結庫的 CFLAGS 參數。(Cflags)

3. pkg-config --libs xxxx
取得該連結庫的 LDFLAGS 參數。(Libs)

4. pkg-config --static xxxx
取得該連結庫供靜態連結的 LDFLAGS 參數。(Libs.private)

5. pkg-config --exists xxx
假如連結庫存在則傳回 0。

6. pkg-config --version
取得 pkg-config 版本號。

7. pkg-config --atleast-pkgconfig-version=VERSION
假如 pkg-config 版本號大於等於 VERSION 則傳回 0。

8. pkg-config --errors-to-stdout
輸出 --print-errors 的錯誤訊息到 stdout 而非 stderr,需搭配 --print-errors 使用。

9. pkg-config --print-errors xxxx
假如連結庫不存在或有問題,則輸出相關錯誤訊息。(好像不太對??)

10. pkg-config --print-requires xxxx
取得連結庫所需的相關連結庫。(Requires)

11. pkg-config --modversion xxxxx
取得連結庫的版本號。(Version)

12. pkg-config --variable=VARIABLENAME xxxx
取得連結庫 .pc 檔案內的變數值。(prefix,exec_prefix,libdir,includedir)

13. .pc 檔案製作
# blkid pkg-config
# 註解
prefix=/usr
exec_prefix=/usr
libdir=/usr/lib
includedir=/usr/include
#上面四個都是變數,視情況可自行增加

Name: blkid
Description: Block device id library
Version: 1.39
Requires: uuid devmapper
Cflags: -I${includedir}
Libs: -L${libdir} -lblkid -ldevmapper

Note that variable references are written "${foo}"; you can escape literal "${" as "$${".
Name: 連結庫名稱
This field should be a human-readable name for the package. Note that it is not the name passed as an argument to pkg-config.
Description: 連結庫描述
    This should be a brief description of the package
URL: 連結庫的來源網站
An URL where people can get more information about and download the package
Version: 連結庫版本
    This should be the most-specific-possible package version string.
Requires: 連結庫相依連結庫名稱
    This is a comma-separated list of packages that are required by your package. Flags from dependent packages will be merged in to the flags reported for your package. Optionally, you can specify the version of the required package (using the operators =, <, >, >=, <=); specifying a version allows pkg-config to perform extra sanity checks. You may only mention the same package one time on the Requires: line. If the version of a package is unspecified, any version will be used with no checking.
Conflicts: 連結庫相依連結庫版本限制
    This optional line allows pkg-config to perform additional sanity checks, primarily to detect broken user installations. The syntax is the same as Requires: except that you can list the same package more than once here, for example "foobar = 1.2.3, foobar = 1.2.5, foobar >= 1.3", if you have reason to do so. If a version isn't specified, then your package conflicts with all versions of the mentioned package. If a user tries to use your package and a conflicting package at the same time, then pkg-config will complain.
Libs: 連結庫編譯所需的 LDFLAGS 參數
This line should give the link flags specific to your package. Don't add any flags for required packages; pkg-config will add those automatically.
Libs.private: 連結庫編譯所需的 LDFLAGS 參數,給靜態庫用的。
    This line should list any private libraries in use. Private libraries are libraries which are not exposed through your library, but are needed in the case of static linking.
Cflags: 連結庫編譯所需的 CFLAGS 參數
    This line should list the compile flags specific to your package. Don't add any flags for required packages; pkg-config will add those automatically.

創作者介紹

邱小新の工作筆記

台南小新 發表在 痞客邦 PIXNET 留言(0) 人氣()