介子不理解 libhandy 库依赖

问题描述

我正在构建一个包含 gtk 和 libhandy 库的应用程序。我正在尝试将 libhandy 捆绑到我的项目中。我正在使用介子构建系统。要将依赖项添加到介子,我遵循了此处的以下文档 1

我已将 libhandy 库克隆到我的项目中 project_root/subprojects/libhandy/ 这是我的 project_root/meson.build 文件

project('githandytest','c',version: '0.1.0',meson_version: '>= 0.50.0',default_options: [ 'warning_level=2','c_std=gnu11',],)

libhandy_dep = dependency('libhandy-0.0',version: '>= 0.0.13')
if not libhandy_dep.found()
  libhandy = subproject(
    'libhandy',install: false,default_options: [
      'examples=false','package_subdir=my-project-name','tests=false',]
  )
  libhandy_dep = libhandy.get_variable('libhandy_dep')
endif

i18n = import('i18n')

config_h = configuration_data()
config_h.set_quoted('PACKAGE_VERSION',meson.project_version())
config_h.set_quoted('GETTEXT_PACKAGE','githandytest')
config_h.set_quoted('LOCALEDIR',join_paths(get_option('prefix'),get_option('localedir')))
configure_file(
  output: 'githandytest-config.h',configuration: config_h,)
add_project_arguments([
  '-I' + meson.build_root(),language: 'c')


subdir('data')
subdir('src')
subdir('po')
subdir('subprojects')

meson.add_install_script('build-aux/meson/postinstall.py')

我包含 <libhandy.h>文件是位于 project_root/src 的 main.c 这是project_root/src/meson.build

githandytest_sources = [
  'main.c'
]

githandytest_deps = [
  dependency('gio-2.0',version: '>= 2.50'),dependency('gtk+-3.0',version: '>= 3.22'),dependency('libhandy-0.0')
]

gnome = import('gnome')

executable('githandytest',githandytest_sources,dependencies: githandytest_deps,install: true,)

由于我使用 flatpak 进行分发,因此我还向项目清单添加了源。

{
    "app-id" : "org.example.App","runtime" : "org.gnome.Platform","runtime-version" : "3.38","sdk" : "org.gnome.Sdk","command" : "githandytest","finish-args" : [
        "--share=network","--share=ipc","--socket=fallback-x11","--socket=wayland"
    ],"cleanup" : [
        "/include","/lib/pkgconfig","/man","/share/doc","/share/gtk-doc","/share/man","/share/pkgconfig","*.la","*.a"
    ],"modules" : [
        {
            "name" : "githandytest","builddir" : true,"buildsystem" : "meson","sources" : [
                {
                    "type" : "git","url" : "file:///home/davtyan/Projects/githandytest"
                }
            ]
        },{
      "name" : "libhandy","config-opts": [
        "-Dexamples=false","-Dtests=false"
      ],"sources" : [
        {
          "type" : "git","url" : "https://source.puri.sm/Librem5/libhandy.git"
        }
      ]
    }
    ]
}

我在运行项目时遇到的问题是:project_root/meson.build:9:0: ERROR: Dependency "libhandy-0.0" not found,tried pkgconfig and cmake

对于这么含糊的问题,我深表歉意。我对介子构建系统非常陌生,无法弄清楚为什么会发生这种情况。如果有帮助,我正在使用 gnome-builder IDE。

解决方法

看起来不需要第二次创建依赖对象dependency('libhandy-0.0')并使用已经创建的:

githandytest_deps = [
  dependency('gio-2.0',version: '>= 2.50'),dependency('gtk+-3.0',version: '>= 3.22'),libhandy_dep
]

我的意思是你有这个错误,因为它试图找到(使用 pkg-config)这个依赖,而不是查看你对 libhandy_dep 的评估。

但是,请注意,此依赖项(pkg-config + 子项目)的评估可以简化为:

libhandy_dep = dependency('libhandy-0.0',version: '>= 0.0.13',fallback : ['libhandy','libhandy_dep'],default_options: ['examples=false','package_subdir=my-project-name','tests=false'])

docs 起:

['subproj_name','subproj_dep'],第一个值是 子项目,第二个是该子项目中的变量名称 包含一个依赖对象,如返回值 声明依赖或依赖(),

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...