2

I am trying to get my machine's number of cpus in vala.
According to http://valadoc.org/#!wiki=glib-2.0/index

public uint get_num_processors ()

should return this to me.

But when I try to compile the following code:

public class Main {
    static int main(string[] args) {
    uint num_cpus = GLib.get_num_processors();
        return 0;   
    }
}

with:

valac --target-glib 2.38 --pkg gtk+-3.0 --pkg gee-1.0 $(SRC)

I see the following error:

Application.vala:28.4-28.26: error: The name 'get_num_processors' does not exist in the context of 'GLib'

I've tested some other methods from GLib. They all work flawless except this one. Has anyone an idea what I'm doing wrong?

4

2 回答 2

2

The function was only added to the VAPI recently, I believe you'll need version 0.22.0 of Vala (or one of the unstable 0.21.x releases).

To get around this you can create a local binding in your code:

[CCode (cname = "g_get_num_processors")]
private extern static uint get_num_processors ();
于 2013-10-02T17:26:42.000 回答
2

这是在 GLib 2.36 中引入的(参见GLib 线程)。你有安装那个版本吗?

于 2013-10-02T15:06:58.913 回答