pkg-config使用学习

本文介绍了pkg-config这个工具,它用于查找系统中已安装库的相关信息,包括编译器和链接器参数。文章详细讲解了在Ubuntu上安装pkg-config的方法,以及如何配置搜索路径和查看、设置变量。还展示了如何使用pkg-config来管理依赖和获取头文件路径。
摘要由CSDN通过智能技术生成

pkg-config是用于查找在系统中已安装的库的工具,它可以查找库的信息包括:

  • 编译器所需要的参数–cflags
  • 链接器所需要的参数–libs
  • 软件包的版本信息等

在Ununtu中pkg-config的安装方法:

sudo apt-get install pkg-config

pkg-config会默认搜索 /usr/lib/pkgconfig和/usr/share/pkgconfig下的 .pc 配置文件,或者将搜索文件夹加入PKG_CONFIG_PATH环境变量,例如:

PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/[库名字]

下面是gtk±3.0 .pc文件内容的例子:

prefix=/usr
exec_prefix=${prefix}
libdir=/usr/lib/x86_64-linux-gnu
includedir=${prefix}/include
targets=x11 broadway wayland

gtk_binary_version=3.0.0
gtk_host=x86_64-pc-linux-gnu

Name: GTK+
Description: GTK+ Graphical UI Library
Version: 3.22.30
Requires: gdk-3.0 atk >= 2.15.1 cairo >= 1.14.0 cairo-gobject >= 1.14.0 gdk-pixbuf-2.0 >= 2.30.0 gio-2.0 >= 2.49.4
Requires.private: atk atk-bridge-2.0 wayland-client >= 1.9.91 wayland-protocols >= 1.12 xkbcommon >= 0.2.0 wayland-cursor >= 1.9.91 wayland-egl  epoxy >= 1.0 pangoft2 gio-unix-2.0 >= 2.49.4
Libs: -L${libdir} -lgtk-3
Cflags: -I${includedir}/gtk-3.0

pkg-config的使用方法:

pkg-config --help

Usage:
  pkg-config [OPTION?]

Help Options:
  -h, --help                              Show help options

Application Options:
  --version                               output version of pkg-config
  --modversion                            output version for package
  --atleast-pkgconfig-version=VERSION     require given version of pkg-config
  --libs                                  output all linker flags
  --static                                output linker flags for static linking
  --short-errors                          print short errors
  --libs-only-l                           output -l flags
  --libs-only-other                       output other libs (e.g. -pthread)
  --libs-only-L                           output -L flags
  --cflags                                output all pre-processor and compiler flags
  --cflags-only-I                         output -I flags
  --cflags-only-other                     output cflags not covered by the cflags-only-I option
  --variable=NAME                         get the value of variable named NAME
  --define-variable=NAME=VALUE            set variable NAME to VALUE
  --exists                                return 0 if the module(s) exist
  --print-variables                       output list of variables defined by the module
  --uninstalled                           return 0 if the uninstalled version of one or more module(s) or their dependencies will be used
  --atleast-version=VERSION               return 0 if the module is at least version VERSION
  --exact-version=VERSION                 return 0 if the module is at exactly version VERSION
  --max-version=VERSION                   return 0 if the module is at no newer than version VERSION
  --list-all                              list all known packages
  --debug                                 show verbose debug information
  --print-errors                          show verbose information about missing or conflicting packages (default unless --exists or --atleast/exact/max-version given on the command line)
  --silence-errors                        be silent about errors (default when --exists or --atleast/exact/max-version given on the command line)
  --errors-to-stdout                      print errors from --print-errors to stdout not stderr
  --print-provides                        print which packages the package provides
  --print-requires                        print which packages the package requires
  --print-requires-private                print which packages the package requires for static linking
  --validate                              validate a package's .pc file
  --define-prefix                         try to override the value of prefix for each .pc file found with a guesstimated value based on the location of the .pc file
  --dont-define-prefix                    don't try to override the value of prefix for each .pc file found with a guesstimated value based on the location of the .pc file
  --prefix-variable=PREFIX                set the name of the variable that pkg-config automatically sets

例如引入头文件:

# pkg-config --cflags-only-I [lib_name]
pkg-config --cflags-only-I gtk+-3.0

/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
  • 15
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据您提供的引用内容和,错误使用 mexopencv.make>pkg_config (line 333) OpenCV library path not found: D:\wangjie\opencv\build\x64\mingw\lib 是由于在配置mexopencv时没有正确设置OpenCV库的路径所导致的。具体来说,D:\wangjie\opencv\build\x64\mingw\lib 这个路径下没有找到OpenCV库。 要解决这个问题,您可以按照以下步骤进行操作: 1. 确保您已经正确安装了OpenCV。请检查您的OpenCV安装路径是否与您在mexopencv.make文件中指定的路径一致。 2. 打开mexopencv.make文件,找到pkg_config函数所在行(line 333),确保函数中指定的OpenCV库路径与您的实际安装路径匹配。 3. 检查OpenCV库路径是否正确设置。可以尝试修改该路径,确保指向正确的OpenCV库路径。您可以使用命令行工具确定正确的OpenCV库路径。 4. 运行mexopencv.make文件,确保在编译过程中正确加载OpenCV库。如果仍然出现错误,请检查您的编译环境和配置是否正确。 总而言之,错误提示表明mexopencv无法找到OpenCV库的路径,请确保已正确设置OpenCV库的路径,并进行必要的更改和调整以解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Opencv学习1: 在Linux下编译运行第一个opencv程序](https://blog.csdn.net/wjxxy2196/article/details/70837806)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李71~李先森

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值