Difference between revisions of "WxHaskell/Building"

From HaskellWiki
Jump to navigation Jump to search
(Changed "cd contrib/src" to "cd ../contrib/src" and "contib" to "contrib")
(Add --partial option to darcs get command)
Line 31: Line 31:
   
 
<pre>&gt; cd ~/dev
 
<pre>&gt; cd ~/dev
&gt; darcs get --set-scripts-executable http://code.haskell.org/wxhaskell/</pre>
+
&gt; darcs get --partial --set-scripts-executable http://code.haskell.org/wxhaskell/</pre>
   
 
=== Getting wxWidgets ===
 
=== Getting wxWidgets ===

Revision as of 02:43, 29 October 2008

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 and 8 (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.4.x, 2.5.x, and 2.6.x.
  • macosx. Mac OS X 10.2 (Jaguar) and 10.3 (Panther) with ghc 6.2.x and wxMAC 2.4.2 and 2.5.x.
  • unix-gtk. Red Hat Linux 10 (Fedora), FreeBSD, and Gentoo Linux, using wxGTK 2.4.2, 2.5.x, and 2.6.x.

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

Prerequisites

Ensure you have a recent GHC compiler – version 6.8.1 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 only works with wxWidgets version 2.4.2 on Windows platforms.

Next, you should install the previous stable version (2.6.4) of wxWidgets for your platform. (wxHaskell doesn't support latest stable version (currently 2.8.4) now.) We assume in this guide that the variable $wxwin points to your wxWidgets installation directory, for example: ~/dev/wxGTK-2.6.4.

  • windows: ghci only works with wxWidgets 2.4.2. Since this wxWidgets version is very stable, it is recommended on windows platforms.
  • macosx: MacOS X works best with wxWidgets 2.5.4. The previous stable release (wxMAC-2.6.4) does not display menus properly.

If you have a source release of wxHaskell, just unpack it in a suitable directory. In the following descriptions, we assume that the variable $wxhaskell points to your installation directory, for example: ~/dev/wxhaskell.

(Note: GHC 6.6.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/

Getting wxWidgets

wxHaskell 0.10.x does not yet support wxWidgets 2.8 (on the other hand, the current darcs version of wxhaskell only supports it). Generally, the recommended version to use is 2.6.4 [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, unless you really want to compile from source and to report back on how everything works out.
    • Leopard - the darcs version of wxhaskell now (2008-04-25) supports wxWidgets 2.8. We don't know if the one that ships with Leopard works yet. Want to give it a try? Otherwise, we do know that it runs with a self compiled wxMac.
  • Linux - the wxWidgets that ships with your system (as long as it's the 2.6 one and not the 2.8 one) should work.

See the wxWidgets site for more details.

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. (--enable-wave on wxWidgets 2.4.x. And 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. (recommended for wxWidgets version >= 2.6.x)
  • 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

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 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++.
  • ghc 6.0.1, wxhaskell 0.8: In the file wxcore/src/Graphics/UI/WXCore/WxcObjects.hs you need to switch the parameters to newForeignPtr on line 172. In the file wx/src/Graphics/UI/WX/Controls.hs you need to replace the import of Data.Typeable by Data.Dynamic.

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 --package-conf=~/mypackages
  • You can generate documentation with make doc.
  • The libraries can be uninstalled with make uninstall.

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!