Tuesday, March 22, 2011

On Windows: How to install GTK

Sometimes, we look for provide a graphic interface to our programs, and, after analyze various options, we decide to use gtk. However, type cabal install gtk will not be enough to have installed the library. As various problems can arise during the installation, I decided to write this little step-to-step guide available for everyone interested.

Step 1 - Getting GTK

First, download the all-in-one bundle of gtk. At the moment of this writing, the version you need is 2.16, but it may change in the future. You will get a compressed file. Decompress it in a path without spaces (for instance: .../gtk), and add to your PATH environment variable the directory .../gtk/bin. You will need this directory in your PATH not only for the installation, but also for executing your gtk-based programs. Otherwise, you will need to copy all DLL's needed for your program in the folder where it is running.
I don't know why, but spaces will do your installation fail. Official documentation alerts of this. What surprised me was that the pkg-config (and all others in the gtk binaries directory) command still works, despite of the spaces. This should not confuse you.

Step 2 - MinGW

Search in your Haskell Platform folder the directory mingw/bin, and add it to your PATH environment variable. I think this step is only necessary for the installation, although I can not confirm it yet.

Step 3 - Build tools

The gtk package can not be installed directly, it needs another package to be installed first, and cabal-install is not able to figure that it is necessary. So, before the gtk package, we install the gtk2hs-buildtools package:

> cabal install gtk2hs-buildtools

Step 4 - Install GTK

And finally, we are ready to install gtk in the traditional way:

> cabal install gtk

It will take a large time. At least, it will take it for me.

Haskell Platform and gtk

Currently, there is a bug that prevents you to install gtk on the version 2011.2.0.0 of the Haskell Platform. You must use an older version of the platform (2010.2.0.0 works).

Reporting problems

While using gtk you may found problems, bugs or, perhaps, you have a request for a new feature in the package. For these purposes, visit the Gtk2Hs bug tracker.

Final notes

Another guides on this topic can be found at:
I tried to merge everything I have read, and my own experience, filtering the necessary information to get gtk working. I hope it helps.

New notes (June 06, 2011)

I've tested the gtk installation with the Haskell Platform 2011.2.0.1 and it throws the same error (while cabal install gtk):

Registering glib-0.12.0(cairo-0.12.0)...
setup.exe: internal error: unexpected package db stack: [UserPackageDB]


5 comments:

Unknown said...

Thank you man!

Unknown said...

I just updated the gtk all-in-one bundle link.

Anonymous said...
This comment has been removed by a blog administrator.
Siffran said...

Hello, I know it's a long time ago but I had this exact problem in 2020. It still hasn't been patched.

First of all, I want to thank you. I had been trying to fix this for two days straight before I found this which in the end fixed it for me. You were correct when you noted that the 2010 version of Haskell worked but not the 2011. This is because 2011 was the first version with a 64-bit installer.

Solution: use the 32-bit installer of Haskell instead of the 32-bit installer.

Siffran said...

Typo: Use the 32-bt installer instead of the 64-bit installer ofc.