pkg-config命令使用
来源:互联网 发布:重庆大学教育网络 编辑:程序博客网 时间:2024/05/22 06:32
pkg-config
是在编译应用程序和库时使用的辅助工具。它可以帮助您在命令行中插入正确的编译器选项,以便应用程序可以使用 gcc -o test test.c pkg-config --libs --cflags glib-2.0
,而不是在何处找到glib(或其他库)的硬编码值。这是语言无关的,所以它可以用于定义文档工具的位置。
概念
pkg-config的主要用途是提供编译和链接程序到库的必要细节。此元数据存储在pkg-config文件中。这些文件具有后缀 .pc并且驻留在pkg-config工具已知的特定位置
prefix=/usr/localexec_prefix=${prefix}includedir=${prefix}/includelibdir=${exec_prefix}/libName: fooDescription: The foo libraryVersion: 1.0.0Cflags: -I${includedir}/fooLibs: -L${libdir} -lfoo
各参数的意义:
Name: 库或软件包的可读名称Description: 简要说明URL: 一个网址,人们可以获取更多的信息和下载包Version: 专门定义包的版本的字符串Requires: 此包所需的包的列表。可以使用比较运算符=,<,>,<=或> =来指定这些包的版本(依赖关系)Requires.private: 该包所需的私有包的列表,但不暴露于应用程序。Conflicts: 描述与此冲突的软件包的可选字段Cflags: 该包的特定编译器标志以及不支持pkg-config的所有库。如果所需的库支持pkg-config,则应将其添加到 Requires或Requires.privateLibs: 特定于此程序包的链接标志以及不支持pkg-config的所有库
编写pkg-config文件
当为一个包创建pkg-config文件时,首先需要决定如何分发它们。每个文件最好用于描述单个库,因此每个包应至少与安装库一样多的 pkg-config文件。
特点:
- pkg-config文件最好每个文件对应一个库文件。
包名通常通过pkg-config元数据文件的名称来确定,.pc后缀的文件名称和库的名称相匹配。
例如:
libfoo.so
的软件包 将具有一个包含pkg-config元数据的对应libfoo.pc
文件Name
,Description
和URL
是纯信息描述容易添加,version
比较棘手,要确保用户数据使用。Requires
,Requires.private
,Cflags
,Libs
和Libs.private
将定义外部项目使用的元数据的编译和链接库
Requires
, Requires.private
都是确定依赖关系的,Requires链接的库文件会暴露出来,Requires.private
依赖的静态的链接库。 libs
使用该库的链接标志 Cflags
使用库的编译器标志
使用pkg-config
系统两个模块foo和bar,pc文件如下:
foo.pc:prefix=/usrexec_prefix=${prefix}includedir=${prefix}/includelibdir=${exec_prefix}/libName: fooDescription: The foo libraryVersion: 1.0.0Cflags: -I${includedir}/fooLibs: -L${libdir} -lfoobar.pc:prefix=/usrexec_prefix=${prefix}includedir=${prefix}/includelibdir=${exec_prefix}/libName: barDescription: The bar libraryVersion: 2.1.2Requires.private: foo >= 0.7Cflags: -I${includedir}Libs: -L${libdir} -lbar
–modversion 显示版本号
$ pkg-config --modversion foo1.0.0$ pkg-config --modversion bar2.1.2
–libs 打印每个模块所需的链接标志
$ pkg-config --libs foo-lfoo$ pkg-config --libs bar-lbar
–static 显示静态链接库
模块bar使用的lfoo库,但是只使用–libs没有显示,但是在系统调用的使用在libdir下查找对应的库文件。
$ pkg-config --libs --static bar-lbar -lfoo
输出所有的cflags
$ pkg-config --cflags bar-I/usr/include/foo$ pkg-config --cflags --static bar-I/usr/include/foo
–exists 查看模块的可用性
$ pkg-config --exists foo$ echo $?0
依赖模块版本检查
$ pkg-config --libs "bar >= 2.7"Requested 'bar >= 2.7' but version of bar is 2.1.2
–print-errors 打印详细的结果
$ pkg-config --exists --print-errors xoxoPackage xoxo was not found in the pkg-config search path.Perhaps you should add the directory containing `xoxo.pc'to the PKG_CONFIG_PATH environment variableNo package 'xoxo' found
pkg-config命令的环境变量
PKG_CONFIG_PATH
是pkg-config的查找路径,在unix系统中查找路径为/usr/lib/pkgconfig
和/usr/share/pkgconfig
但是有的安装在/usr/lib
目录下,所以最好提前制定好环境变量
$ pkg-config --modversion hello ``` Package hello was not found in the pkg-config search path. Perhaps you should add the directory containing `hello.pc' to the PKG_CONFIG_PATH environment variable No package 'hello' found ```$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig$ pkg-config --modversion hello1.0.0
参考链接
指导文档
- pkg-config命令使用
- pkg-config命令了解和使用
- Linux中 `pkg-config` 命令的使用
- pkg-config命令了解和使用
- pkg-config命令
- pkg-config命令
- Linux命令pkg-config
- Linux命令pkg-config
- Linux命令 pkg-config
- pkg-config命令讲解
- pkg-config命令详解
- pkg-config命令
- pkg-config使用
- pkg-config的使用
- pkg-config使用
- pkg-config的使用
- pkg-config的使用
- pkg-config的使用
- matlab2c使用c++实现matlab函数系列教程-abs函数
- SSH整合(配置文件)
- 圆环的颜色切换与速度控制
- Codeforces 851A
- 网易2018校招内推--整数数列
- pkg-config命令使用
- <netty权威指南>笔记-分隔符解码器处理半包问题
- JavaScript专业八级测试,你能做对几道?
- Ubuntu系统如何更改用户密码
- HTML常用标签
- easyui Combotree默认选中第一项
- JS中AOP的实现和运用
- ie6_hack 图片显示问题
- Mabatis多表关联注意事项