如何在anjuta项目中包含资源文件
问题描述:
我试图更新vala中的图形项目,将很多代码行移动到一个ui文件中。 我想使用模板(可用于glib-2.38和GTK + 3.8,类似的)。如何在anjuta项目中包含资源文件
我的项目由Anjuta和autoconf管理。
在src
目录下有
application.ui
:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.8 -->
<template class="SpiWindow" parent="GtkApplicationWindow">
<property name="title" translatable="yes">Example Application</property>
<property name="default-width">600</property>
<property name="default-height">400</property>
<child>
<placeholder />
</child>
</template>
</interface>
resources.xml
:
<?xml version="1.0" charset="UTF-8" ?>
<gresources>
<gresource prefix="/org/app/spi">
<file compressed="true" preprocess="xml-stripblanks">application.ui</file>
</gresource>
</gresources>
在src/Makefile.am
我有追加--gresources resources.xml
到spi_VALAFLAGS
。最后我声明了Gtk.ApplicationWindow
这样
[GtkTemplate(ui = "/org/app/spi/application.ui")]
internal class SpiWindow : Gtk.ApplicationWindow {
// Constructor
public Window (Gtk.Application application) {
Object(application: application);
}
}
但是,当我编译,然后运行该应用程序,有错误消息:
(spi:9749): Gtk-CRITICAL : Unable to load resource for composite template for type 'SpiWindow': The resource at '/org/app/spi/application.ui' does not exist
(spi:9749): Gtk-CRITICAL : gtk_widget_init_template: assertion 'template != NULL' failed
答
你仍然需要编译的资源,并将它们包括:
GLIB_COMPILE_RESOURCES=glib-compile-resources
resources.c: resources.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies resources.xml)
$(GLIB_COMPILE_RESOURCES) [email protected] --generate-source $<
并且包括resources.c
作为spi_SOURCES
中的源文件。
谢谢,我试图使用作为模式的猴面包树makefile,但我错过了构建的C文件应该添加到spi_SOURCES的部分。 – 2014-10-08 21:39:47