Personal tools

WxHaskell/Building

From HaskellWiki

< WxHaskell
Revision as of 21:53, 3 January 2009 by M (Talk | contribs)

Jump to: navigation, search

Contents

1 Building from sources

In principle we recommend the use of binary releases, but wxHaskell also has a build system to compile directly from sources. The build process has been specialized for three main platforms:

  • unix-gtk. General unix systems with GTK.
  • macosx. Mac OS X.
  • windows. General windows systems (i.e. win95 to winXP). We support both building with the Microsoft Visual C++ compiler version 6, 7, 8 and 9 (windows-msc) and building with the gnu mingw32 C compiler (windows-mingw).

wxHaskell has been build successfully on (at least) the following configurations:

  • windows. Windows 98, windows 2000, and windowsXP, using wxMSW 2.8.x.
  • macosx. Mac OS X 10.4 (Tiger) and 10.5 (Leopard) with ghc 6.10.x and wxMAC 2.8.x.
  • unix-gtk. Red Hat Linux 10 (Fedora), FreeBSD, and Gentoo Linux, using wxGTK 2.8.x.

(Unfortunately, there are still build problems on Sun Solaris – we are looking for build volunteers :-)

2 Prerequisites

Ensure you have a recent GHC compiler – version 6.8.1 or higher is recommended (but any version >= 5.04.3 will work). In principle, any Haskell98 compiler that supports the standard FFI libraries will also work.

  • windows: you need the cygwin environment together with the mingw compiler. The build process is very sensitive to the cygwin setup and there is a separate guide for installing cygwin properly.
  • macosx: you need to install the gcc compiler, which is part of the Apple Developer Tools. These tools are shipped with Panther and are installed by invoking Applications/Installers/Developer Tools/Developer.mdmg.
  • ghci: the GHCi interpreter doesn't works well on Windows platforms (works well with wxWidgets version 2.4.2. But we no longer support old stable version).

Next, you should install the current stable version (2.8.9) of wxWidgets for your platform. (wxHaskell doesn't support old stable version any more.) We assume in this guide that the variable $wxwin points to your wxWidgets installation directory, for example: ~/dev/wxGTK-2.8.9.

(Note: GHC 6.10.x or higher can't build old source releases. So you must get source from darcs by below command.)

If you do not have a source release of wxHaskell, you need to check it out from the darcs repository. Darcs creates a wxhaskell directory for you; we assume in the following example that your $wxhaskell directory will be ~/dev/wxhaskell.

> cd ~/dev
> darcs get --partial --set-scripts-executable http://code.haskell.org/wxhaskell/

3 Getting wxWidgets

wxHaskell 0.11.x supports wxWidgets 2.8. And wxHaskell doesn't support wxWidgets 2.6 any more. Generally, the recommended version to use is 2.8.x [2.6.3 on Debian/Ubuntu Linux] as it's what the binaries are compiled against.

  • Windows:
    • Binary - you can skip this phase. you should just install wxHaskell. Because wxHaskell's dll statically links wxWidgets library.
  • MacOS X
    • Tiger - do not use the wxMac 2.5 that comes pre-installed.
    • Leopard - wxhaskell now supports wxWidgets 2.8.
  • Linux - the wxWidgets that ships with your system (as long as it's the 2.8 one and not the 2.6 one) should work.

See the wxWidgets site for more details.

3.1 building wxWidgets on Windows

For those who wish to build wxHaskell directly on Windows, this section describes how to build the wxWidgets prerequisite using standard GNU tools -- there is a separate section on building the library with Microsoft Visual C++ on windows.

According to the wxWidgets preferred installation, create a mybuild directory in the wxWidgets directory, and run configure and make from that directory (and take the time to get some coffee :-).

> cd $wxwin
> mkdir mybuild
> cd mybuild
> ../configure --enable-unicode
> make
> make install
> cd ../contrib/src
> make
> make install

Notes:

  • Add the following flags to configure, to enable certain advanced features of wxHaskell:
    • --enable-unicode to build a unicode library (required for 0.10 and up).
    • --with-odbc to enable database access.
    • --with-opengl to enable the openGL canvas.
    • --enable-sound to enable playback of wave audio files. (This option is diffrent with below option. You can play sound without no-control by this feature. But ... if you use below media control, it requires to make Control on your Window.)
    • --enable-mediactrl to enable the media control.
    • --enable-graphics_ctx to enable the graphics contexts.
  • Do not forget to run make install; this installs a utility called wx-config that is used by the other projects.
  • Do not forget to install 'contrib' hierarchy libraries. Now latest darcs' source depends on 'contrib' hierarchy libraries.
  • unix-gtk: if you want to use the GTK-2 toolkit, you need to configure with unicode support since current wxHaskell can handle only unicode library. Try for example:
    ../configure --with-gtk --enable-gtk2 --enable-unicode
  • macosx: you might need to run rehash after make install in order to add the wx-config utility to the search path cache.
  • windows: sometimes the header file $wxwin\include\wx\msw\popupwin.h is not properly copied when make install is run, and you need to copy it manually to the install directory (for example /usr/local/include/wx/msw). (if this file is not copied, C compilation of wxHaskell will fail).

Now try out a few samples of wxWidgets to see if it all works correctly:

> cd ../../samples/controls
> make
> ./controls

Note that you build from the local samples directory that resides in the mybuild directory.

And also try if wx-config works too:

> wx-config --version

4 Building wxHaskell

First, we configure the library for your platform.

> cd $wxhaskell
> ./configure --enable-split-objs --hcprof

Notes:

  • You can run configure first with the --help option. This also shows the values of command-line options and is an excellent check to see if everything is set up correctly. If the settings do not make sense, it might be that the wx-config utility is not found – maybe you have forgotten to run make install on wxWindows?
  • You should pass the --with-opengl option to configure if you specified this flag when configuring wxWidgets (or you will get link errors).
  • You should pass the --with-contrib option to configure if you also installed contrib libraries after building wxWidgets (or you will get link errors).
  • By default, the library is installed in the wxWidgets install directory. You can use users directory by user option: ./configure --user. And you can specify another directory with the prefix option of configure: ./configure --prefix=/usr/local. Any directory that is on your library search path will do.
  • windows-msc. Read the notes on building wxHaskell with Visual C++.
  • If you used the Debian/Ubuntu backport from above, then you should use both the --with-opengl option and the --with-contrib option.

After configuration, we build and install the libraries (and take some more time to drink more coffee :-).

> make
> make install
> make wx
> make wx-install

Notes:

  • If make install fails when building the ghc package, you might not have administrator priviliges. Either run it as an administrator or configure in such a way that you use a local ghc package:
    ./configure --user

    or:

    ./configure --package-conf=~/mypackages
  • You can generate documentation with make doc.
  • The libraries can be uninstalled with make uninstall.

4.1 building by cabal command

Cabal doesn't works well currently. This is Cabal and cabal (install)'s problem (e.g. 394, 431). And current cabal 0.6.0's dependency solver has problem.

So, you should build and install wxHaskell by hand (at least wxcore package).

If you want to build and install wxHaskell by cabal command, you must use following command.

> cabal install wx --configure-opt="--user --enable-split-objs --hcprof"

or

> sudo cabal install wxcore --global
> cabal install wx

5 Test wxHaskell

If everything succeeded, you should be able to run a test program.

> cd samples/wx
> ghc -package wx -o helloworld HelloWorld.hs
> ./helloworld

Notes:

macosx: Unfortunately, wxHaskell programs do not work directly as generated by GHC. Look at the MacOS X notes for more information. You can also run the examples from GHCi – a great development environment!

> ghci -package wx BouncingBalls.hs
> main

Notes:

wxHaskell programs are not always properly reïnitialized when started the second time from a GHCi prompt. This is due static variables in the wxWidgets C++ code, and we are working with wxWidgets developers to remove those bugs. Currently, GHCi only works well with wxWidgets 2.4.2. gtk: Unfortunately, one can only start a wxWidgets program once with GHCi on GTK (rendering it useless). macosx. You need to use a special command to run wxHaskell applications, see the Mac OS X notes from more information. Have fun!