← 返回命令列表

Linux command

pkg-config 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Get compiler flags

pkg-config --cflags [library]

Get linker flags

pkg-config --libs [library]

Get all flags

pkg-config --cflags --libs [library]

Check if library exists

pkg-config --exists [library] && echo "Found"

Get library version

pkg-config --modversion [library]

List all packages

pkg-config --list-all

说明

pkg-config retrieves compiler and linker flags needed to build software against installed libraries. It reads metadata from .pc files that libraries install, providing the correct include paths, library paths, and link flags. Build systems like autotools, CMake, and Meson use pkg-config to locate libraries portably. The --cflags flag returns compiler flags (include paths), --libs returns linker flags, and --modversion shows the installed version. Version constraints can be checked with --atleast-version.

参数

--cflags
Compiler flags.
--libs
Linker flags.
--exists
Check existence.
--modversion
Show version.
--list-all
List packages.
--atleast-version _VERSION_
Exit successfully if version is at least VERSION.
--exact-version _VERSION_
Exit successfully if version matches exactly.
--max-version _VERSION_
Exit successfully if version is at most VERSION.
--variable _NAME_
Print the value of a variable defined in the .pc file.
--libs-only-L
Print only -L/-R library search path flags.
--libs-only-l
Print only -l library name flags.
--cflags-only-I
Print only -I include path flags.
--static
Output for static linking (include private dependencies).
--print-errors
Show errors when package not found.
--silence-errors
Suppress error output.

FAQ

What is the pkg-config command used for?

pkg-config retrieves compiler and linker flags needed to build software against installed libraries. It reads metadata from .pc files that libraries install, providing the correct include paths, library paths, and link flags. Build systems like autotools, CMake, and Meson use pkg-config to locate libraries portably. The --cflags flag returns compiler flags (include paths), --libs returns linker flags, and --modversion shows the installed version. Version constraints can be checked with --atleast-version.

How do I run a basic pkg-config example?

Run `pkg-config --cflags [library]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --cflags do in pkg-config?

Compiler flags.