GTK2HS Installation under Windows and Haskell/GUI Programming with GTK2HS

13 Feb 2011 02:00 | Baxılıb: 632

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 in (d:gtkin) 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 in to to PATH (environmental) variable (I’ve installed Haskell Platform to D:Haskell Platform2010.2.0.0, so my path is D:Haskell Platform2010.2.0.0mingwin).

     

  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 Adamovs 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

Haskell/GUI Programming with GTK2HS. Advanced Hello World

Filed under: Programming and Development Tagged: | linkedin

Son yeniliklər


Azərbaycan komandaları 41-ci ACM ICPC 2016-2017 NEERC Təl...

Azərbaycan komandaları 41-ci ACM ICPC 2016-2017 NEERC Tələbələrin Beynəlxalq Proqramlaşdırma Müsabiqəsinin yarımfin ətraflı oxu »

Qafqaz Universitetində “41-ci ACM ICPC - Universitet Tələ...

Qafqaz Universiteti, Bakı Dövlət Universiteti, ADA Universiteti, NAPCAR, IEEE Computer Society Azərbaycan Bölm ətraflı oxu »

Qafqaz Universitetində Mühəndislər Günləri 2016 Keçirildi...

Qafqaz Universitetində Mühəndislər Günləri 2016 Keçirildi E-days16 (Engineering days) ətraflı oxu »

Microsoft Azərbaycanın Nümayəndəsi Kompüter Mühəndisliyi ...

Microsoft Azərbaycanın Nümayəndəsi Kompüter Mühəndisliyi tələbələrinə təcrübə keçmə imkanla ətraflı oxu »