【问题标题】:valac --vapi --internal-vapi --fast-vapivalac --vapi --internal-vapi --fast-vapi
【发布时间】:2016-10-28 10:33:00
【问题描述】:
// Point.vala
namespace Test {
    class Point {
        public const int MY_CONST = 123;
        public float x { get; set; }
        public float y { get; set; }
    }
}

有一个vala源文件,'Point.vala'

  1. --vapi

valac --vapi=Point.vapi --library=point -X -shared Point.vala:

// Point.vapi
namespace Test {
}

空...

  1. --internal-vapi

valac --internal-vapi=Point.vapi --header=Point.h --internal-header=Point_internal.h --library=point -X -shared Point.vala:

// Point.vapi
namespace Test {
    [CCode (cheader_filename = "Point_internal.h")]
    internal class Point {
        public const int MY_CONST;
        public Point ();
        public float x { get; set; }
        public float y { get; set; }
    }
}

它看起来很完美,适合我

  1. --fast-vapi

valac --fast-vapi=Point.vapi --library=point -X -shared Point.vala:

// Point.vapi
using GLib;
namespace Test {
    internal class Point {
        public const int MY_CONST = 123; // error
        public Point ();
        public float x { get; set; }
        public float y { get; set; }
    }
}

这会在使用这个 vapi 时引发错误,error: External constants cannot use values

Q1:确切的区别是什么?以及为什么有这些选项。

Q2:为了创建共享库,我应该使用--internal-vapi吗?

【问题讨论】:

    标签: vala vapi


    【解决方案1】:

    您的类没有指定其可见性,因此默认情况下它具有“内部”可见性。

    这意味着它只对您命名空间内的其他类可见。

    如果您将类指定为 public,--vapi 开关将按预期输出一个 vapi 文件:

    // Point.vala
    namespace Test {
        // Make it public!
        public class Point {
            public const int MY_CONST = 123;
            public float x { get; set; }
            public float y { get; set; }
        }
    }
    

    调用:

    valac --vapi=Point.vapi --library=point -X -shared Point.vala
    

    结果:

    /* Point.vapi generated by valac.exe 0.34.0-dirty, do not modify. */
    
    namespace Test {
            [CCode (cheader_filename = "Point.h")]
            public class Point {
                    public const int MY_CONST;
                    public Point ();
                    public float x { get; set; }
                    public float y { get; set; }
            }
    }
    

    所以--vapi 将只输出公共类型,--internal-vapi 还将输出内部类型。

    我不知道--fast-vapi 是干什么用的。

    关于您的第二个问题,您通常应该将公共类用于共享库。内部与公共可见性的重点在于,公共类型是供公众(在命名空间之外)使用的,而内部类型仅用于内部实现细节。

    【讨论】:

    • 谢谢! 'If an access modifier for the class is not given, the default "public" is used' 是错误信息? (也许老了?)
    • --fast-vapi--use-fast-vapi 用于parallel builds。它旨在为每个 Vala 文件生成一个 C 源代码,以便我们可以同时启动多个 valac 实例。但是,这需要了解源之间的依赖关系。此信息通过传递--deps 提供。
    • 手册中的条目现已更新为“如果未给出类的访问修饰符,则使用默认的“内部””
    猜你喜欢
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    相关资源
    最近更新 更多