Difference between revisions of "Gtk2Hs"

From HaskellWiki
Jump to navigation Jump to search
(delete outdated links + update some of the information)
 
(10 intermediate revisions by 7 users not shown)
Line 7: Line 7:
 
== Homepage ==
 
== Homepage ==
   
http://haskell.org/gtk2hs/
+
http://projects.haskell.org/gtk2hs/
   
 
== Tutorials and Demos ==
 
== Tutorials and Demos ==
Line 21: Line 21:
 
== Status ==
 
== Status ==
   
  +
See [[Gtk2Hs/Installation#Supported_Versions]] for details on which systems should be able to build Gtk2Hs and which are known to be able to build Gtk2Hs.
It currently works with Gtk+ 2.0 through to 2.22 on Unix, Win32 and MacOS X.
 
Details please check : http://www.gtk.org/language-bindings.html
 
 
It currently builds with ghc 5.04.3 through to 7.xx.x (6.12.2 have runtime bug, don't use it)
 
   
 
== Installation Notes ==
 
== Installation Notes ==
=== Windows 7 32 bit ===
 
==== Changing Environment Variables ====
 
This installation process involves adding/modifying environment variables. The rest of this subtopic shows you how to do that in Windows.
 
* Using the Environment Variable GUI
 
** Click to the Windows symbol on the bottom-left where "Start" used to be
 
** Right-Click on "Computer", choose "Properties" and click the link for "Advanced System Settings"
 
** In the *top* window, Click "New" add a variable or click "Edit" to modify an existing one.
 
** The variable should be a ';' seperated list of directories.
 
* At the DOS prompt
 
** To see the current value of variable VAR:
 
> echo %VAR%
 
** To modify variable VAR:
 
> set %VAR%=%VAR%;dir1;dir2 ...
 
** To create variable VAR:
 
> set %VAR%=dir1;dir2....
 
==== Install Haskell Platform and MingW ====
 
* Install the [http://hackage.haskell.org/platform/windows.html Haskell Platform] for Windows.
 
* Optional : Install [http://mingw.org MinGW] as per the instructions on their web site. Also install MSYS and mingw-make. A version of MinGW does come with Haskell Platform but excludes MSYS and 'make'.
 
==== Install libxml ====
 
* Download and unzip the latest libxml2 and libxml2-dev archives from [http://ftp.gnome.org/pub/GNOME/binaries/win32/dependencies/ Gnome].
 
* To the PKG_CONFIG_PATH environment variable add the 'pkgconfig' directory in libxml2-dev.
 
* To the INCLUDE environment variable add the path to the 'include' directory from libxml2-dev.
 
 
==== Install the GTK/Glade bundle ====
 
* Download and install the [http://ftp.gnome.org/pub/GNOME/binaries/win32/glade3/3.6/glade3-3.6.7-with-GTK+.exe bundled GTK and Glade binary].
 
* To the PKG_CONFIG_PATH environment variable add the 'pkgconfig' directory. The default path should be "C:\Program Files\Gtk+\lib\pkgconfig".
 
* To the INCLUDE environment variable add the 'libglade-2.0' directory. The default path should be "C:\Program Files\Gtk+\include\libglade-2.0".
 
==== Install the Haskell bindings ====
 
* At the DOS prompt run 'cabal install gtk2hs-buildtools'.
 
* At the DOS prompt run 'cabal install gtk'. Make sure you have at least 1.5 GB RAM otherwise this compilation will die.
 
* At the DOS prompt run 'cabal install glade'.
 
==== Test the GTK install ====
 
* In some appropriate temporary directory run 'cabal unpack gtk'. This downloads and unpacks the Haskell sources.
 
** Run the demos (using mingw-make)
 
*** If you installed MinGW then in the 'demo' directory, navigate into the 'hello' directory and run mingw32-make.exe. Now run the executable that was created.
 
** Run the demos (manual compilation)
 
*** In the 'demo' directory, navigate into the 'hello' directory and run 'ghc --make World.hs -o helloworld.exe'. Now run the executable that was created.
 
==== Test the Glade install ====
 
* In some appropriate temporary directory run 'cabal unpack glade'. This downloads and unpacks the Haskell sources.
 
** Run the demos (using mingw-make)
 
*** If you installed MinGW then in the 'demo' directory, navigate into the 'gladetest' directory and run mingw32-make.exe. Now run the executable that was created.
 
** Run the demos (manual compilation)
 
*** In the 'demo' directory, navigate into the 'gladetest' directory and run 'ghc --make GladeTest.hs -o gladetest.exe'. Now run the executable that was created.
 
 
==== Common Errors ====
 
* Glade.h is not found
 
gtk2hsC2hs.exe : glade/glade.h: File does not exist
 
Probably instead of installing the GTK/Glade bundle you installed them seperately. The GTK/Glade bundle comes with the "include/libglade-2.0" containing a number of header files. For some reason this directory is not included in stand-alone GTK and Glade installers. Install the bundle and add this directory to the INCLUDE environment variable.
 
* Cabal cannot find gtk2hsC2hs.
 
Please install gtk2hs-buildtools' first and check
 
that the installdirectory is in your PATH (e.g. HOME/.cabal/bin).
 
cabal: Error: some packages failed to install
 
Somehow the path to the cabal bin directory has been lost. To the PATH environment variable re-add the cabal bin directory. The default path should be "%USERPROFILE%\AppData\Roaming\cabal\bin".
 
* Spinner error with the 'notebook' demo
 
Running the 'notebook' demo in the GTK install gives:
 
[1 of 1] Compiling Main ( Notebook.hs, Notebook.o )
 
Notebook.hs:14:35:
 
Not in scope: type constructor or class `Spinner'
 
Notebook.hs:78:13: Not in scope: `spinnerNew'
 
Notebook.hs:101:2: Not in scope: `spinnerStart'
 
Notebook.hs:109:2: Not in scope: `spinnerStop'
 
mingw32-make: *** [notebook] Error 1
 
This happens because this demo uses the new Spinner widget in GTK 2.22. Since this is not available in GTK 2.16 you get this error.
 
 
=== Mac OS X ===
 
 
==== Using MacPorts and Snow Leopard ====
 
 
This explains how to install Gtk2Hs-0.10.1 on Mac OS X 10.6 Snow Leopard, in combination with GTK+ from MacPorts.
 
 
* Install the [http://hackage.haskell.org/platform/ Haskell Platform] for Mac
 
* Download gtk2hs from [http://www.haskell.org/gtk2hs/ gtk2hs website] and untar it.
 
* Install gtk, cairo, etc. from MacPorts like this (note that the +universal is needed; if you already installed gtk or one of its dependencies, it is recommended you reinstall those as detailed in the NB at the end of this section).
 
:::sudo port install gtk +universal
 
* go to the directory where gtk2hs is untarred and run
 
:::./configure --disable-split-objs --disable-gio
 
:::make
 
:::sudo make install
 
 
Alternatively, if you wish to follow the Mac OS X style of directory layout, you can use this configure command instead:
 
:::./configure --with-pkgconf=/Users/username/.ghc/i386-darwin-6.10.4/package.conf --prefix=/Users/username/Library/Haskell/packages/gtk2hs --disable-split-objs --disable-gio
 
 
Where username is your username ofcourse. Right now you should be able to run the demos. Unfortunately, to build any libraries depending on gtk2hs, such as [http://hackage.haskell.org/package/Chart/ Chart], you need to edit one more file. You will need to find "package.conf" for your ghc by doing
 
:::ghc-pkg list
 
In the output you will see the full directory to your package.conf file. In this file, you need to search for "gthread", and everywhere you can find it, add "/opt/local/lib" (with quotes) to the libraryDirs array before it.
 
 
If all went well, it should be properly installed now.
 
 
NB: If compiling fails with architecture errors for certain dynlibs, you need to reinstall the packages these dynlibs belong to with +universal by doing
 
:::sudo port upgrade packagename --enforce-variants +universal
 
Alternatively, and this is recommended, you can follow the steps on [http://passingcuriosity.com/2009/haskell-on-snow-leopard/ Haskell On Snow Leopard Blogpost] to immediately add the universal variant of each package:
 
# Edit /opt/local/macports/variants.conf and add +universal to the end of this file
 
# sudo port selfupdate
 
# sudo port sync
 
# sudo port upgrade --force-installed
 
 
==== Using the GTK+ OS X Framework ====
 
 
This explains how to install Gtk2Hs on Macs using the native [http://gtk-osx.sourceforge.net/ GTK+ OS X Framework], a port of GTK+ to the Mac that does '''not''' depend on X11, and hence, is better integrated into the Mac desktop - i.e., menus actually appear in the menu bar, where they belong. It also avoids the often tedious installation of GTK+ via MacPorts. However, it misses support for optional Gtk2Hs packages that are currently not supported by the [http://gtk-osx.sourceforge.net/ GTK+ OS X Framework], most notably support for Glade. It does include support for Cairo, though.
 
 
Here is how to install the library:
 
# Download and install [http://gtk-osx.sourceforge.net/ GTK+ OS X Framework] (this uses the standard Mac package installer).
 
# Install [http://pkg-config.freedesktop.org/ pkg-config], either by compiling it from source or via MacPorts.
 
# Download and unpack the Gtk2Hs tar ball from the [http://www.haskell.org/gtk2hs/download/ Gtk2Hs download page] (I tested 0.10.0).
 
# Configure with (you may want to remove the two backslashes and put everything on one line)
 
env PKG_CONFIG_PATH=/Library/Frameworks/Cairo.framework/Resources/dev/lib/pkgconfig:\
 
/Library/Frameworks/GLib.framework/Resources/dev/lib/pkgconfig:\
 
/Library/Frameworks/Gtk.framework/Resources/dev/lib/pkgconfig ./configure --disable-gio
 
# Build with
 
make
 
# Install (to <tt>/usr/local/</tt> unless a <tt>--prefix</tt> option was passed to <tt>configure</tt>) with
 
sudo make install
 
 
The library is now registered with the package database of the GHC you used for compiling.
 
 
NB: Thanks to Ross Mellgren for his post on the gtk2hs-users list that outlined the use of <tt>PKG_CONFIG_PATH</tt>.
 
 
==== Article as of Mid 2008 ====
 
Installing Gtk2Hs on Mac requires some finesse, at least until Haskell Libary Platform is built or ghc-6.8.3 is
 
available in macports. (These are planned for late 2008.)
 
 
* Install [http://macports.org MacPorts]
 
* Install dependencies:
 
sudo port install glade3 libglade2 gstreamer gst-plugins-base gtksourceview cairo librsvg gtkglext firefox
 
* Update PKG_CONFIG_PATH (for libraries)
 
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/local/lib/pkgconfig
 
* Update ghc to use macports libs: Edit your main <tt>ghc</tt> driver program and change the last line to:
 
exec $GHCBIN $TOPDIROPT ${1+"$@"} -L/opt/local/lib -I/opt/local/include
 
* Download Gtk2Hs following instructions at [http://www.haskell.org/gtk2hs/downloads/ Gtk2Hs Download page]
 
* Check configuration:
 
./configure --enable-docs --enable-profiling
 
 
...
 
 
**************************************************
 
* Configuration completed successfully.
 
*
 
* The following packages will be built:
 
*
 
* glib : yes
 
* gtk : yes
 
* glade : yes
 
* cairo : yes
 
* svgcairo : yes
 
* gtkglext : yes
 
* gconf : yes
 
* sourceview : yes
 
* mozembed : yes
 
* soegtk : yes
 
* gnomevfs : yes
 
* gstreamer : yes
 
* documentation : yes
 
*
 
* Now do "(g)make" followed by "(g)make install"
 
**************************************************
 
* Build and Install:
 
make
 
sudo make install
 
   
  +
See [[Gtk2Hs/Installation]].
==== Recent experiences ====
 
I successfully installed the latest version on Mac OS 10.5 by:
 
* Installing Macports.
 
* <tt>sudo port install ghc</tt>
 
* <tt>sudo port install gtk2hs</tt> - which does not complete successfully. It does however, install the appropriate dependencies. Note that there are so many, you may need to install a couple of times due to time outs etc.. The build of Gtk2HS will fail, but that is ok - continue as below. Also note that ghc configure will give up if your perl5.8 is not new enough, if so deactivate it and try again.
 
* Remove the build directory under <tt>/opt/.../build/gtk2hs</tt>
 
* Download Gtk2Hs via darcs as per [http://haskell.org/gtk2hs/development/#darcs the gtk2hs download instructions]
 
* do a <tt>sudo port install automake</tt>
 
* do a <tt>sudo port install alex</tt>
 
* do a <tt>sudo port install happy</tt> (Note this also fails and must be built from source. See the [[Happy]] page for details.)
 
* Follow the build instructions on the [http://haskell.org/gtk2hs/development/#darcs the gtk2hs download page]. I would suggest using <tt>./configure --prefix=/opt/local</tt> to get it in the same place as ports - personal preference though.
 
Good luck - as usual, your mileage may vary.
 
   
 
== Demos ==
 
== Demos ==
Line 210: Line 38:
 
These are links to FAQS on the main site.
 
These are links to FAQS on the main site.
 
*[http://haskell.org/gtk2hs/archives/2005/06/23/hiding-the-console-on-windows/#more-26 Hiding the console on windows]
 
*[http://haskell.org/gtk2hs/archives/2005/06/23/hiding-the-console-on-windows/#more-26 Hiding the console on windows]
*[http://haskell.org/gtk2hs/archives/2005/07/24/writing-multi-threaded-guis/#more-38 Writing multi-threaded GUIs]
 
*[http://haskell.org/gtk2hs/archives/2005/06/24/building-from-source-on-windows/#more-15 Building on Windows]
 
 
*[http://haskell.org/gtk2hs/development/#darcs Checkout instructions]. Also see [[Darcs]]
 
*[http://haskell.org/gtk2hs/development/#darcs Checkout instructions]. Also see [[Darcs]]
   

Latest revision as of 20:16, 1 December 2012

What is it?

Gtk2Hs is a Haskell binding to Gtk+ 2.x. Using it, one can write Gtk+ based applications with GHC.

Homepage

http://projects.haskell.org/gtk2hs/

Tutorials and Demos

http://www.haskell.org/haskellwiki/Gtk2Hs/Tutorials

Some demonstration programs can be found at:

http://code.haskell.org/gtk2hs/gio/demo/
http://code.haskell.org/gtk2hs/pango/demo/
http://code.haskell.org/gtk2hs/cairo/demo/
http://code.haskell.org/gtk2hs/gtk/demo/

Status

See Gtk2Hs/Installation#Supported_Versions for details on which systems should be able to build Gtk2Hs and which are known to be able to build Gtk2Hs.

Installation Notes

See Gtk2Hs/Installation.

Demos

OpenGL and Gtk2Hs

Gtk2Hs/Demos/GtkGLext/hello.hs

Gtk2Hs/Demos/GtkGLext/terrain.hs requires Gtk2Hs/Demos/GtkGLext/terrain.xpm

FAQs

These are links to FAQS on the main site.