Domanda

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?

È stato utile?

Soluzione

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 ();

Altri suggerimenti

This was introduced in GLib 2.36 (see GLib Threads). Do you have that version installed?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top