Vala 0.18.1 hello world in Ubuntu 12.10

After this tutorial you’ll learn how to compile your first vala GTK program
Screenshot from 2013-01-19 00:22:05

Prepare your system:

# add the GPG key for the vala team PPA
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 7DAAC99C
# add the PPA to your Software Sources
sudo add-apt-repository ppa:vala-team
# update the package lists
sudo apt-get update
# install vala
sudo apt-get install valac-0.18 vala-0.18-doc valac-0.18-dbg
valac --version

# optionally install other PPA packages
# libgee - collections library
sudo apt-get install libgee-dev 

# install gtk-dev
sudo apt-get install libgtk-3-dev

Save program text to hello.vala file:

using Gtk;
 
int main (string[] args) {
    Gtk.init(ref args);
 
    var window = new Window();
    window.title = "Hello, World!";
    window.border_width = 10;
    window.window_position = WindowPosition.CENTER;
    window.set_default_size(350, 70);
    window.destroy.connect(Gtk.main_quit);
 
    var label = new Label("Hello, World!");
 
    window.add(label);
    window.show_all();
 
    Gtk.main();
    return 0;
}

Compile and launch the prog:

valac --pkg gtk+-3.0 hello.vala && ./hello
Tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *