Compile and run Vala on Windows using MinGW-builds

A quick tutorial how you can compile the valac compiler on Windows 8.1 to compile and run Vala programs.

 

    1. Download MinGW-builds from http://sourceforge.net/projects/mingwbuilds/
    2. Run "mingw-builds-install.exe", select "x32" as Architecture, "win32" as Threads and "sjlj" as Exception:

    3. Continue installation, I placed my to "C:\mingw-builds"
    4. Download the latest "external-binary-packages" from http://sourceforge.net/projects/mingwbuilds/files/external-binary-packages/ and copy the "msys" directory to "C:\mingw-builds\mingw32"
    5. Open "‪C:\mingw-builds\mingw32\msys\etc\fstab" with Notepad++ and add the line "C:\mingw-builds\mingw32 /mingw".
    6. Download the Win32 GTK+ "all-in-one bundle" from http://www.gtk.org/download/win32.php and extract it's content to "C:\mingw-builds\mingw32".
    7. Create a new shortcut, e.g. on the Desktop and set the location to "C:\mingw-builds\mingw32\msys\bin\mintty.exe /bin/bash -l" in order to get a nice shell.
    8. Download the latest source tarball from https://wiki.gnome.org/Projects/Vala/Release and extract it to "C:\mingw-builds\mingw32\msys\home\{Your Username}".
    9. Run the Mintty shortcut you created in step 7 and switch with "cd" to the vala source directory.
    10. Now you should be able to run the fallowing three commands without any issues:
      ./configure --prefix=/mingw --host=i686-w64-mingw32
      make
      make install
    11. Run "valac" to see if it works:
      $ valac --version
      Vala 0.22.1
    12. Go to "Control Panel\System and Security\System" -> "Advanced system settings" ->  "Environment Variables" and add this to your "Path" system variable:
      C:\mingw-builds\mingw32\bin
    13. Create somewhere a file called "hello.vala" and paste in this:
      using Gtk;
      
      int main (string[] args) {
          Gtk.init (ref args);
      
          var window = new Window ();
          window.title = "First GTK+ Program";
          window.border_width = 10;
          window.window_position = WindowPosition.CENTER;
          window.set_default_size (350, 70);
          window.destroy.connect (Gtk.main_quit);
      
          var button = new Button.with_label ("Click me!");
          button.clicked.connect (() => {
              button.label = "Thank you";
          });
      
          window.add (button);
          window.show_all ();
      
          Gtk.main ();
          return 0;
      }
    14. Open a normal Windows CMD, cd to the location of the file and run "valac --pkg gtk+-3.0 -X -mwindows hello.vala"
    15. Execute the compiled "hello.exe", you should see your first Vala GTK+ window, congratulation Cool: