• meson和pkg-config


    最近再看simple-cam,它是用meson构建的。

    有这样一句:

    1. deps = [
    2. dependency('libevent-pthreads'),
    3. ]

    执行编译时报错:

    meson.build:16:0: ERROR: Dependency "libevent_pthreads" not found, tried pkgconfig and cmake

    但实际上libevent_pthreads我已经用apt安装过了,但是为什么还找不到?

    原因是meson使用pkg-config来查找依赖项:

    Pkg-config is a way for shared libraries to declare the compiler flags needed to use them.

    那么原因就是pkg-config没有找到libevent-pthread。

    pkg-config是如何查找到各种library的?它通过一些.pc文件来查找。

    首先,我们可以用pkg-config查看所有的安装包:

    pkg-config --list-all

    然后,用下面代码查看pkg-config执行时搜索的文件:

    1. $ pkg-config --variable pc_path pkg-config
    2. /usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig

    在这些目录下添加自己编写的pc文件即可。

    比如:

    1. prefix=/usr/local
    2. includedir=${prefix}/include
    3. libdir=${prefix}/lib/x86_64-linux-gnu
    4. Name: libcamera
    5. Description: Complex Camera Support Library
    6. Version: 0.0.0
    7. Requires: libcamera-base
    8. Libs: -L${libdir} -lcamera
    9. Cflags: -I${includedir}/libcamera

    其中,libdir是通过`dpkg -L`来看到的。我们看一下libevent_pthreads的情况:

    1. $ dpkg -L libevent-pthreads-2.1-6
    2. /.
    3. /usr
    4. /usr/lib
    5. /usr/lib/x86_64-linux-gnu
    6. /usr/lib/x86_64-linux-gnu/libevent_pthreads-2.1.so.6.0.2
    7. /usr/share
    8. /usr/share/doc
    9. /usr/share/doc/libevent-pthreads-2.1-6
    10. /usr/share/doc/libevent-pthreads-2.1-6/copyright
    11. /usr/lib/x86_64-linux-gnu/libevent_pthreads-2.1.so.6
    12. /usr/share/doc/libevent-pthreads-2.1-6/changelog.Debian.gz

    可以看出,没有头文件。看来不能用apt来安装它、必须用源码安装的方式。我们从libevent.org上下载libevent的源码,执行configure、make和sudo make install,可以看到:

    1. Libraries have been installed in:
    2. /usr/local/lib
    3. /usr/bin/install -c -m 644 libevent.pc libevent_core.pc libevent_extra.pc libevent_pthreads.pc libevent_openssl.pc '/usr/local/lib/pkgconfig'

    查看/usr/local/lib/pkgconfig/libevent_pthreads.pc:

    1. #libevent pkg-config source file
    2. prefix=/usr/local
    3. exec_prefix=${prefix}
    4. libdir=${exec_prefix}/lib
    5. includedir=${prefix}/include
    6. Name: libevent_pthreads
    7. Description: libevent_pthreads adds pthreads-based threading support to libevent
    8. Version: 2.1.12-stable
    9. Requires: libevent
    10. Conflicts:
    11. Libs: -L${libdir} -levent_pthreads
    12. Libs.private:
    13. Cflags: -I${includedir} -pthread

    再执行pkg-config --list-all就可以看到libevent_pthread了。

    然后执行meson build也可以顺利的找到libevent_pthread这个依赖项。

  • 相关阅读:
    WPF性能优化:Freezable 对象
    sklearn包中对于分类问题,如何计算accuracy和roc_auc_score?
    计算S=a+aa+…+aa…a
    基于JAVA旅游景点推荐系统计算机毕业设计源码+数据库+lw文档+系统+部署
    面试题:什么是Reids的击穿、穿透、雪崩三种现象?如何解决?
    算法每日一题(反转单链表)C语言版
    【业务场景】用户连点
    无线城市WiFi解决方案【完整Word】
    Spring源码解析(十二):TransactionInterceptor事务拦截器
    总结springboot项目中一些后端接收前端传参的方法
  • 原文地址:https://blog.csdn.net/zinnc/article/details/125474483