Friday, March 11, 2011

Haskell GTK on Windows (part 2)

Updated Blog Entry

There seems to be some issues with the documentation as it relates to install GTK and Haskell (at least at present). There are two steps that need to be highlighted if they aren't already.

Task-Remove Install Paths with Spaces:

GTK has an windows installer like most windows apps and normally you would install the application/library to C:/Program[SPACE]Files/GTK[PLUS-SIGN]. Don't do that. The default install of GTK haskell win32 did not seem to work. I recommend the simple:

Install to: C:/gtk

Task-Setup mingw/bin in your PATH env:

Also, you may need to use the mingw install that comes with the haskell platform. Navigate to Haskell Platform/mingw/bin and copy that path and add it to your PATH environment variable setting.

Before doing this, you may see errors, cpp.exe is not found or other such compile errors. Adding mingw adds some of those compiler tools.

Optional

The glade/gtk bundle install to C:/gtk may not have all the dev libraries that you need. Install the bundle first and then visit the gtk site and download the gtk dev packages. Unzip and overwrite to the C:/gtk directory.

Run 'cabal install gtk' again...

More information:

C:\Documents and Settings\Usr Berlin]echo %PATH%
C:\Program Files\Gtk+\bin;C:\Program Files\Haskell\bin;C:\Program Files\Haskell
Platform\2010.2.0.0\lib\extralibs\bin;C:\Program Files\Haskell Platform\2010.2.0
.0\bin; ... and other stuff

C:\Documents and Settings\Usr Berlin>echo %PKG_CONFIG_PATH%
C:\Program Files\Gtk+\lib\pkgconfig;C:\Program Files\Gtk+\include\libglade-2.0;C
:\Program Files\libxml2\libxml2-dev_2.7.7-1_win32\lib\pkgconfig


C:\Documents and Settings\Usr Berlin>echo %INCLUDE%
C:\Program Files\Gtk+\include;C:\Program Files\libxml2\libxml2-dev_2.7.7-1_win32
\include;C:\Program Files\Gtk+\include\libglade-2.0;C:\Program Files\Gtk+\includ
e

C:\Documents and Settings\Usr Berlin]pkg-config.exe --modversion gtk+-2.0
2.16.2

C:\Documents and Settings\Usr Berlin]pkg-config --cflags gtk+-2.0
Files/Gtk+/include/gtk-2.0 -mms-bitfields Files/Gtk+/lib/gtk-2.0/include Files/G
tk+/include/atk-1.0 Files/Gtk+/include/cairo Files/Gtk+/include/pango-1.0 Files/
Gtk+/include/glib-2.0 Files/Gtk+/lib/glib-2.0/include Files/Gtk+/include/libpng1
2 -IC:/Program

C:\Documents and Settings\Usr Berlin]cabal update
Downloading the latest package list from hackage.haskell.org

C:\Documents and Settings\Usr Berlin]cabal install gtk

GTK versions

The GTK version is important. I installed the glade bundle (glade3/3.6/glade3-3.6.7-with-GTK+.exe) but I also downloaded the (gtk+/2.16/gtk+-bundle_2.16.6-20100912_win32.zip) zip file and unpacked, unpacked that archive to the c:/gtk directory. Note, I am installing everything GTK to the c:/gtk directory as opposed to Program Files directory.

Edit: if you have issues with glib.h not being found.

Run 'cabal install -v'. Add the -v verbose flag enable more verbose logging during the compile. You may see that glib.h is not found. I didn't pick a clean solution, I simply just copied the 'glib-2.0' directory (contains the glib.h header file) into the glib-2.0 directory. So you will have:

C:\gtk\include\glib-2.0\glib-2.0

Edit-2:
I ran 'cabal install glade' and got an error trying to install. I searched the mailing list for a solution.

Navigate to the pkgconfig directory and open the libglade pc file:

C:\gtk\lib\pkgconfig\libglade-2.0.pc

Requires: gtk+-2.0 libxml-2.0

Comment out the line with gtk+-2.0... and ensure that the line only has:

Requires: gtk+-2.0

Hopefully, that will resolve compile issues with glade.

GHC Haskell version: ghc-6.12.3

Summary

You may have issues with the wiki documentation on building with GTK under windows. Start with installing GTK to a directory that does not include spaces or non-alphanumeric characters. Setup your PATH to point to a the Haskell/mingw/bin directory to pick up the mingw compiler tools. Setup the PATH, INCLUDE, PKG_CONFIG... environment variables (these should be correct in the wiki document). Check your glib.h file and make sure it is included (maybe setup glib-2.0/glib-2.0/*.h, glib.h). For glade (cabal install glade), modify the libglade-2.0.pc configuration.

Resources

[1] http://www.haskell.org/haskellwiki/Gtk2Hs

Example Hello World Source (ghc --make Hello.hs)
import Graphics.UI.Gtk
main = do
initGUI
window <- windowNew
widgetShowAll window
mainGUI

No comments:

Post a Comment