如何在Vala中导入其他文件

如何在Vala中导入其他文件

本文介绍了如何在Vala中导入其他文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题几乎说明了一切-如何将file2.vala导入到file1.vala?

The question pretty much says it all- how could I import file2.vala to file1.vala?

推荐答案

您不直接这样做.如果运行valac file1.vala file2.vala,就好像您将它们编译到一个大文件中一样.

You don't do it directly. If you run valac file1.vala file2.vala, it is as if you compiled them in one big file.

如果要使其可重用,则可能需要共享库.在这种情况下,您可以编译生成一个C头文件和一个VAPI定义:

If you want to make them reusable, then you probably want a shared library. In which case, you compile one to produce a C header file and a VAPI definition:

valac --vapi file1.vapi -H file1.h --library libfile1.so file1.vala

第二个可以吃掉这个:

valac --pkg file1 file2.vala

这假定已安装VAPI文件.如果不是这种情况,则需要传递--vapidirfile1.vapi所在的位置,可能是..同样,您还需要将file1.h-X -I/directory/containing一起存放的地方告知C编译器,可能又是-X -I..最后,您需要通过-X -L/directory/containing -X -lfile1告诉C链接器libfile1.so的位置.这是针对特定平台的,您可以使用AutoMake消除差异,尽管这涉及更多. Ragel是如何与Vala一起使用AutoMake的常用项目.

This assume that the VAPI file has been installed. If this is not the case, you'll need to pass --vapidir and the location where file1.vapi exists, probably .. Similarly, you'll need to inform the C compiler about where file1.h lives with -X -I/directory/containing, again, probably -X -I.. Finally, you'll need to tell the C linker where libfile1.so is via -X -L/directory/containing -X -lfile1. This is a little platform specific, and you can smooth the difference out using AutoMake, though this is a bit more involved. Ragel is the usual go-to project for how to use AutoMake with Vala.

这篇关于如何在Vala中导入其他文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 02:22