Flatpak Meson无法从Gnome Builder中找到Vala库 [英] Flatpak Meson Not Finding Vala Libraries From Gnome Builder

查看:192
本文介绍了Flatpak Meson无法从Gnome Builder中找到Vala库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,我正在Gnome Builder(3.26.4)中使用Meson(0.44.0)作为将使用Gee和GXml的控制台程序.我的目的是用Genie编写.

From Linux, I'm using Meson (0.44.0) within Gnome Builder (3.26.4) for a console program that will use Gee and GXml. My intent is to write this in Genie.

当我在Gnome Builder中使用Meson时,它会失败,但是使用valac(0.38.8)从命令行中调用时,会成功,如下所示:

When I use Meson within Gnome Builder it fails but the same succeeds when invoked from the command line using valac (0.38.8) as follows:

valac --pkg=gtk+-3.0 --pkg=gee-0.8 --pkg=gxml-0.16 main.gs

以上内容均无错误.我尝试使用gee和gxml设置meson.build为依赖项,或者将其设置为 vala_args .同样的错误.

There is no error from the above. I've tried setting up meson.build with gee and gxml as dependency and alternatively as vala_args. Same error.

检查pkg-config,我得到以下信息:

Checking pkg-config, I get the following:

$ pkg-config --libs gxml-0.16
-L/usr/local/lib64 -lgxml-0.16 -lgio-2.0 -lxml2 -lgee-0.8 -lgobject-2.0 -lglib-2.0
$ pkg-config --libs gee-0.8
-lgee-0.8 -lgobject-2.0 -lglib-2.0
$ pkg-config --libs gee-1.0
-lgee -lgobject-2.0 -lglib-2.0

也许我做错了.这是本地meson.build文件,其后是顶级meson.build和错误:

Perhaps I'm doing something wrong. Here is the local meson.build file followed by the top level meson.build and the error:

example_sources = [
  'main.gs'
]

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

gnome = import('gnome')

example_sources += gnome.compile_resources(
  'example-resources',
  'example.gresource.xml',
  c_name: 'example'
)

executable(
  'example',
  example_sources,
  vala_args: '--target-glib=2.50 --pkg=gee-0.8 --pkg=gxml-0.16',
  dependencies: example_deps,
  install: true
)

具有顶级meson.build:

with top-level meson.build:

project(
  'example',
  ['c', 'vala'],
  version: '0.1.0',
  meson_version: '>= 0.40.0',
)

subdir('src')

错误是:

uses Gee

error: The namespace name 'Gee' could not be found

我正在从Gnome-Builder中调用构建.有人可以帮助我了解发生了什么吗?我试图在文档中找到为什么valac成功而介子失败,但是找不到解决方案.

I'm invoking the build from within Gnome-Builder. Can someone help me understand what is happening? I've tried to find why valac succeeds and meson fails in the documentation but cannot find a solution.

推荐答案

Gee和GXml应该是依赖项,就像GIO,GLib和GTK +一样.因此,您应该尝试:

Gee and GXml should be dependencies, just like GIO, GLib and GTK+. So you should try:

example_deps = [
  dependency('gio-2.0', version: '>= 2.50'),
  dependency('gtk+-3.0', version: '>= 3.22'),
  dependency('glib-2.0', version: '>= 2.50'),
  dependency('gobject-2.0'),
  dependency('gee-0.8'),
  dependency('gxml-0.16'),
  ]

通常,您无需超出此范围.这使得vala_flags中的--pkg选项是不必要的.介子会为您做到这一点. Meson的工作方式是使用valac生成C代码,然后在单独的阶段使用C编译器生成二进制代码.通过使用--pkg,您仅告诉valac要使用哪个VAPI文件,而没有通知C编译器要为C库使用哪个pkg-config软件包.

Usually you won't need to go beyond that. This makes the --pkg options in the vala_flags unnecessary. Meson does that for you. The way Meson works is it uses valac to produce C code then in a separate stage uses a C compiler to produce the binary. By using --pkg you are only telling valac which VAPI file to use, but not notifying the C compiler which pkg-config package to use for the C library.

还要注意,我已经添加了gobject-2.0作为依赖项.如果我没记错的话,GNOME Builder会错过这一点,并且会影响构建.

Also notice I've added gobject-2.0 as a dependency. If I remember correctly GNOME Builder misses that and it does affect the build.

错误消息error: The namespace name 'Gee' could not be found令人不安.这是Vala编译器的错误,我以为编译器将能够使用您尝试过的vala_args方法找到VAPI文件.也许您是从源头构建了Gee,但未在系统范围内安装它?

The error message, error: The namespace name 'Gee' could not be found, is troubling. This is an error from the Vala compiler and I would have thought that the compiler would be able to find the VAPI file using the vala_args method you've tried. Maybe you have Gee built from source and not installed system wide?

介子确实允许添加另一个VAPI搜索目录:

Meson does allow another VAPI search directory to be added:

add_project_arguments(['--vapidir',
                       join_paths(meson.current_source_dir(), 'vapi')
                      ],
                      language: 'vala'
                     )

有关Meson Build文档的 Vala页面,有更多详细信息.

There are more details on the Vala page of the Meson Build documentation.

Genie支持已添加到版本0.42的Meson中.所以meson_version:应该是>= 0.42.0.

Genie support was added to Meson with version 0.42. So meson_version: should be >= 0.42.0.

如果仍然存在问题,则可以使用Genie,Gee和Meson的 MCVE .这应该从命令行编译.将以下Genie程序另存为genie-gee.gs:

If there are still problems then here is an MCVE using Genie, Gee and Meson. This should be compiled from the command line. Save the following Genie program as genie-gee.gs:

[indent=2]
uses Gee

init
  var my_list = new ArrayList of string()
  my_list.add( "one" )
  my_list.add( "two" )
  for item in my_list
    print( item )

然后将以下介子文件另存为meson.build:

Then save the following Meson file as meson.build:

project('minimal-genie-gee-example',
        'vala', 'c'
        )

genie_gee_deps = [
                dependency('glib-2.0'),
                dependency('gobject-2.0'),
                dependency('gee-0.8'),
                ]

executable('genie-gee',
           'genie-gee.gs',
           dependencies: genie_gee_deps
           )

从命令行使用Meson设置构建目录:

From the command line use Meson to set up the build directory:

meson setup builddir

这应该显示已找到依赖项,例如:

This should show the dependencies have been found, for example:

Native dependency gee-0.8 found: YES 0.18.0

然后使用 Ninja build 构建项目:

ninja -C builddir

对于使用Fedora的任何人,ninjaninja-build.

For anyone using Fedora ninja is ninja-build.

任何有关Meson设置构建目录的问题都会记录到builddir/meson-logs/meson-log.txt.

Any problems with Meson setting up the build directory are logged to builddir/meson-logs/meson-log.txt.

如果这可行,但是在GNOME Builder中失败,那么我唯一的想法是已经使用Flatpak安装了GNOME Builder. Flatpak的沙盒环境可能会影响对依赖项的访问.

If this works, but it fails in GNOME Builder, then my only other thought is that GNOME Builder has been installed using Flatpak. The sandboxed environment of Flatpak may be affecting the access to dependencies.

更新:在注释中的讨论之后,似乎是GNOME Builder使用的运行时出现了问题. Builder具有一个很棒的功能,它能够选择用于构建软件的Flatpak运行时.如果您通过在工作站上安装库和头文件来遵循传统"开发方式,请确保已选择 Host Operating System (主机操作系统),而不是Flatpak运行时.看来GNOME Flatpak运行时不包含libgee.

Update: Following the discussion in the comments it appears the runtime used by GNOME Builder was the problem. Builder has a great feature of being able to select the Flatpak runtime used to build your software. If you are following the 'traditional' way of developing by installing libraries and header files on your workstation then make sure Host Operating System is selected instead of a Flatpak runtime. It would appear the GNOME Flatpak runtime does not include libgee.

Update2 :在编写Flatpak构建器清单时,如果Flatpak运行时/SDK中没有依赖项,则将该依赖项添加为Flatpak构建器清单中的另一个模块.这使GNOME Builder可以使用Flatpak在Flatpak运行时中构建软件. AsymLabs答案中提供了一个清单清单示例.

Update2: When writing a Flatpak builder manifest and a dependency is not in the Flatpak runtime/SDK then add the dependency as another module in the Flatpak builder manifest. This allows GNOME Builder to use Flatpak to build the software with the Flatpak runtime. An example manifest is given in AsymLabs answer.

这篇关于Flatpak Meson无法从Gnome Builder中找到Vala库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆