For faster navigation, this Iframe is preloading the Wikiwand page for pkg-config.

pkg-config

此条目没有列出任何参考或来源。 (2023年7月10日)维基百科所有的内容都应该可供查证。请协助补充可靠来源改善这篇条目。无法查证的内容可能会因为异议提出而被移除。

pkg-config 是一个在原始码编译时查询已安装的的使用接口的电脑工具软件。pkg-config 原本是设计用于 Linux 的,但现在在各个版本的 BSDwindowsMac OS XSolaris 上都有着可用的版本。

它输出已安装的库的相关资讯,包括:

工作原理

当安装一个库时(例如从 RPMdeb 或其他二进制包管理系统),会包括一个后缀名为 pc 的文件,该文件会被放入某个文件夹下(取决于你的系统设置)。例如,在 Linux 为该软件的库文件所在文件夹 lib 之下的子文件夹 pkgconfig。并把该子文件夹加入 pkg-config 的环境变量 PKG_CONFIG_PATH 作为搜索路径,例如在 bash 配置文件中加入一行:

export PKG_CONFIG_PATH=/usr/local/`库的名字`/lib/pkgconfig:$PKG_CONFIG_PATH

在这个 .pc 文件里包含有数个条目。这些条目通常包含用于其他使用这个库的程序编译时需要的库设置,以及头文件的位置,版本资讯和一个简介。

这是一个用于 libpng 的 .pc 文件的样例:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${exec_prefix}/include
 
Name: libpng
Description: Loads and saves PNG files
Version: 1.2.8
Libs: -L${libdir} -lpng12 -lz
Cflags: -I${includedir}/libpng12

这个文件告诉我们这些库可以在 /usr/local/lib 找到,头文件可以在 /usr/local/include 里找到,库的名字是 libpng12 并且版本号是 1.2.8。它也提供了用于编译依赖于 libpng 的原始码时需要的链接器参数。

这是一个编译时使用 pkg-config 的样例:

gcc -o test test.c $(pkg-config --libs --cflags libpng)

{{bottomLinkPreText}} {{bottomLinkText}}
pkg-config
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?