Abzetdin Adamov's IT Blog

IT is about doing more with less!

GTK2HS Installation under Windows and Haskell/GUI Programming with GTK2HS.

Posted by Abzetdin Adamov on December 11, 2010

Haskell WinGHCI Interface

Haskell WinGHCI Interface

Recently I tried to make necessary settings to do GUI programming in Haskell under Windows. It turned out, that it’s not so easy as may seem. There are a lot of contradictory tutorials on the Web. Even, official download address of GTK2HS (www.haskell.org/gtk2hs/download) annonced by many tutorials is not existing now. So the official instructions for building gtk2hs on Windows have out of date information and leave out some important issues, so here’s how I got it all working on Windows XP, I believe steps are same for Windows 7. Now step by step we will go though installation process:

  1. Haskell Platform
    Install latest release from http://hackage.haskell.org/platform/ (I installed version 2010.2.0.0 ) 

  2. GTK+
    Download the GTK+ all-in-one bundle 2.16 version (2.22 has some problems) all-in-one bundle from here http://www.gtk.org/download-windows.html
    Extract to folder you would like (for example d:\gtk)
    Add \bin (d:\gtk\bin) to PATH (environmental) variable.
    Run CMD and check command

    > pkg-config –cflags gtk+-2.0
    If you will get some paths instead of failure message, things are going well

  3. MinGW
    You don’t need to install MinGW separately, it already exists within your Haskell Platform. Only you should do – add MinGW \bin to to PATH (environmental) variable (I’ve installed Haskell Platform to D:\Haskell Platform\2010.2.0.0, so my path is D:\Haskell Platform\2010.2.0.0\mingw\bin).

  4. GTK2HS
    Now you should have everything you need to install gtk2hs from Hackage:

    cabal update
    cabal install gtk2hs-buildtools
    cabal install gtk

Depend on you Internet download speed, computer perfomance and releases of packages we talked above, each step will take some time. Whole process may vary from 20 to 40 minutes.

Congratulation! Now you can make sure that GTK2HS wors properly by running the following advanced “Hello World” code:

import Graphics.UI.Gtk

main :: IO ()
main =
    do initGUI
       win <- windowNew
       windowSetTitle win "Adamov's Example"
       win `onDestroy` mainQuit

       ent <- entryNew
       btn <- buttonNew

       col <- vBoxNew False 5
       containerAdd col ent
       containerAdd col btn

       buttonSetLabel btn "Click to Print"
       entrySetText ent "Hello World"

       btn `onClicked` do s <- entryGetText ent
                          print s

       containerAdd win col
       widgetShowAll win
       mainGUI
Haskell/GUI Programming with GTK2HS. Advanced "Hello World"

Haskell/GUI Programming with GTK2HS. Advanced "Hello World"

Advertisements

2 Responses to “GTK2HS Installation under Windows and Haskell/GUI Programming with GTK2HS.”

  1. Speedy said

    Thank you SO much for this.
    First working tutorial i read (and i read a lot).

    btw. i can confirm this works for Win 7 x64

  2. Faisal said

    Thanks so much… it also works in Windows 8 (DP) after using ghc in command prompt and running exe. But ghci can’t link to cairo… but at least it is working..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

 
%d bloggers like this: