问题描述
我正在尝试使用带有gobject内省的pygi创建到vala库的python绑定.但是,我在生成GIR文件时遇到了麻烦(我打算随后将其编译为typelib文件).根据文档,valac应该支持生成GIR文件.
I am trying to create python bindings to a vala library using pygi with gobject introspection. However, I am having trouble generating the GIR files (that I am planning to compile to typelib files subsequently). According to the documentation valac should support generating GIR files.
编译以下内容
helloworld.vala
public struct Point {
public double x;
public double y;
}
public class Person {
public int age = 32;
public Person(int age) {
this.age = age;
}
}
public int main() {
var p = Point() { x=0.0, y=0.1 };
stdout.printf("%f %f\n", p.x, p.y);
var per = new Person(22);
stdout.printf("%d\n", per.age);
return 0;
}
使用命令
valac helloworld.vala --gir=Hello-1.0.gir
不会像预期的那样创建Hello-1.0.gir
文件.如何生成gir文件?
doesn't create the Hello-1.0.gir
file as one would expect. How can I generate the gir file?
推荐答案
要生成GIR,必须将要导出的函数放在同一命名空间下
To generate the GIR one has to put the functions to be exported under the same namespace
hello.vala
namespace Hello {
public struct Point {
public double x;
public double y;
}
public class Person {
public int age = 32;
public Person(int age) {
this.age = age;
}
}
}
public int main() {
var p = Hello.Point() { x=0.0, y=0.1 };
stdout.printf("%f %f\n", p.x, p.y);
var per = new Hello.Person(22);
stdout.printf("%d\n", per.age);
return 0;
}
,然后运行以下命令.
and then run the following command.
valac hello.vala --gir=Hello-1.0.gir --library Hello-1.0
这将在当前目录中生成一个gir和一个vapi文件.
This will generate a gir and a vapi file in the current directory.
然后生成typelib文件,需要运行
Then to generate the typelib file, one needs to run
g-ir-compiler --shared-library=hello Hello-1.0.gir -o Hello-1.0.typelib
假定共享库已编译为libhello.so
这篇关于如何从Vala编译器生成GIR文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!