Difference between revisions of "WxHaskell/Building"

From HaskellWiki
Jump to navigation Jump to search
(one problem with build solved)
(0.12.1.2 cabal build instructions)
Line 1: Line 1:
=== Building from sources ===
+
=== For the very lazy ===
   
  +
You need to have wxWidgets 2.8.10 installed on your machine (and compiled with MSys g++ if using Windows). Windows users should also get the Windows port of wx-config.
In principle we recommend the use of [[WxHaskell/Download|binary releases]], but wxHaskell also has a build system to compile directly from sources. The build process has been specialized for three main platforms:
 
  +
  +
You have correctly configured all of te recommended wxWidgets environment variables, and have a recent version of GHC with an up to date cabal install.
  +
  +
This is all you need:
  +
  +
> cabal install wx
  +
  +
=== Supported Configurations ===
  +
  +
The build process has been tested against three main platforms:
   
 
* '''unix-gtk'''. General unix systems with GTK.
 
* '''unix-gtk'''. General unix systems with GTK.
 
* '''macosx'''. Mac OS X.
 
* '''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''').
+
* '''windows'''. General windows systems (i.e. win95 to winXP). <br />
  +
We support both building only with the gnu mingw32 C compiler ('''windows-mingw''').<br /> ''Please note that we have discontinued support for Microsoft compilers in the build system.''
  +
 
wxHaskell has been build successfully on (at least) the following configurations:
 
wxHaskell has been build successfully on (at least) the following configurations:
   
Line 15: Line 27:
 
=== Prerequisites ===
 
=== Prerequisites ===
   
Ensure you have a recent [http://www.haskell.org/ghc GHC] compiler – version 6.8.1 or higher is recommended (but any version &gt;= 5.04.3 will work). In principle, any Haskell98 compiler that supports the standard FFI libraries will also work.
+
Ensure you have a recent [http://www.haskell.org/ghc GHC] compiler – version 6.10.3 or higher is recommended. In principle, any Haskell98 compiler that supports the standard FFI libraries along with cabal install should work. We have discontinued support for building without cabal.
  +
  +
* '''windows''': You will need wx-config for Windows, MinGW 5.1.6 and MSys 0.1.11 (these are the latest versions at the time of writing). You must select the C++ compiler option when installing MinGW.
  +
** MinGW 5.1.1 can be downloaded from [http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer MinGW]
  +
** MSys 0.1.11 can be downloaded from [http://downloads.sourceforge.net/mingw/MSYS-1.0.11.exe MSys]
  +
** wx-config can be downloaded from [http://wxconfig.googlepages.com/ wx-config]
   
* '''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 [[WxHaskell/Building_on_Cygwin|guide]] for installing cygwin properly.
 
 
* '''macosx''': you need to install the <tt>gcc</tt> compiler, which is part of the Apple Developer Tools. These tools are shipped with Panther and are installed by invoking <tt>Applications/Installers/Developer Tools/Developer.mdmg</tt>.
 
* '''macosx''': you need to install the <tt>gcc</tt> compiler, which is part of the Apple Developer Tools. These tools are shipped with Panther and are installed by invoking <tt>Applications/Installers/Developer Tools/Developer.mdmg</tt>.
  +
=
* '''ghci''': the GHCi interpreter doesn't work 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 [http://www.wxwidgets.org wxWidgets] for your platform. (wxHaskell doesn't support old stable version any more.) We assume in this guide that the variable <tt>$wxwin</tt> points to your wxWidgets installation directory, for example: <tt>~/dev/wxGTK-2.8.9</tt>.
+
You should install the current stable version (2.8.10) of [http://www.wxwidgets.org wxWidgets] for your platform - versions older than 2.8.1 are no longr supported. Build instructions are given for Windows - on most other platforms you should be able to obtain wxWidgets using your package manager (you may need -developer packages).
   
  +
We assume in this guide that the variable <tt>$wxwin</tt> points to your wxWidgets installation directory, for example: <tt>~/dev/wxGTK-2.8.10</tt>.
(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 [http://code.haskell.org/wxhaskell/ darcs repository]. Darcs creates a <tt>wxhaskell</tt> directory for you; we assume in the following example that your <tt>$wxhaskell</tt> directory will be <tt>~/dev/wxhaskell</tt>.
 
 
<pre>&gt; cd ~/dev
 
&gt; darcs get --partial --set-scripts-executable http://code.haskell.org/wxhaskell/</pre>
 
   
 
=== Getting wxWidgets ===
 
=== Getting wxWidgets ===
   
  +
wxHaskell 0.12.x.x supports wxWidgets > 2.8.
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:
 
* Windows:
  +
** You will need to build using the MinGW compiler - instructions below.
** Binary - you can skip this phase. you should just install wxHaskell. Because wxHaskell's dll statically links wxWidgets library.
 
 
* MacOS X
 
* MacOS X
 
** Tiger - do '''not''' use the wxMac 2.5 that comes pre-installed.
 
** Tiger - do '''not''' use the wxMac 2.5 that comes pre-installed.
** Leopard - wxhaskell now supports wxWidgets 2.8.
+
** 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.
 
* 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.
 
** [http://wiki.wxpython.org/InstallingOnUbuntuOrDebian Backport of wxWidgets 2.8 for Debian and Ubuntu]
 
** [http://wiki.wxpython.org/InstallingOnUbuntuOrDebian Backport of wxWidgets 2.8 for Debian and Ubuntu]
Line 45: Line 56:
 
See [http://wxwidgets.org the wxWidgets site] for more details.
 
See [http://wxwidgets.org the wxWidgets site] for more details.
   
==== building wxWidgets on Windows ====
+
==== 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 [[WxHaskell/Building_on_Windows|section]] on building the library with Microsoft Visual C++ on windows.
 
   
  +
'''Note:''' ''Microsoft compilers are no longer supported. The cabal build system cannot understand the output of wx-config for Microsoft compilers.''
According to the wxWidgets preferred installation, create a <tt>mybuild</tt> directory in the wxWidgets directory, and run <tt>configure</tt> and <tt>make</tt> from that directory (and take the time to get some coffee :-).
 
  +
  +
Using the MSys shell, and making sure that you have the C++ compiler oiption installed for MinGW (it is 'not' the default):
  +
  +
> cd /c/path/to/wxWidgets-2.8.10/build/msw
  +
> mingw32-make -f makefile.gcc BUILD=release MONOLITHIC=1 SHARED=1 UNICODE=1
  +
  +
That's it! A DLL is generated in /c/path/to/wxWidgets/gcc_dll, which you will need to copy to a location where it can be found when running your executables.
  +
  +
==== On Unix systems ====
  +
  +
You should follow the instructions on the wxWidgets website if there are no suitable packages for your environment. You probably want to use GCC to build wxWidgets, as this makes it more likely that cabal will understand the output of wx-config.
  +
  +
On most Unix platforms, wxWidgets build goes something like: create a <tt>mybuild</tt> directory in the wxWidgets directory, and run <tt>configure</tt> and <tt>make</tt> from that directory (and take the time to get some coffee :-).
   
 
<pre>&gt; cd $wxwin
 
<pre>&gt; cd $wxwin
Line 60: Line 84:
 
&gt; make
 
&gt; make
 
&gt; make install</pre>
 
&gt; make install</pre>
  +
Notes:
 
  +
==== Testing wxWidgets build ====
<ul>
 
<li>Add the following flags to <tt>configure</tt>, to enable certain advanced features of wxHaskell:
 
<ul>
 
<li><tt>--enable-unicode</tt> to build a unicode library (required for 0.10 and up).</li>
 
<li><tt>--with-odbc</tt> to enable [http://wxhaskell.sourceforge.net/doc/Graphics-UI-WXCore-Db.html database access].</li>
 
<li><tt>--with-opengl</tt> to enable the [http://wxhaskell.sourceforge.net/doc/Graphics-UI-WXCore-OpenGL.html openGL canvas].</li>
 
<li><tt>--enable-sound</tt> to enable playback of wave audio files. (This option is different 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.)</li>
 
<li><tt>--enable-mediactrl</tt> to enable the media control.</li>
 
<li><tt>--enable-graphics_ctx</tt> to enable the graphics contexts.</li></ul>
 
</li>
 
<li>Do not forget to run <tt>make install</tt>; this installs a utility called <tt>wx-config</tt> that is used by the other projects.</li>
 
<li>Do not forget to install 'contrib' hierarchy libraries. Now latest darcs' source depends on 'contrib' hierarchy libraries.</li>
 
<li>'''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:
 
<pre>../configure --with-gtk --enable-gtk2 --enable-unicode</pre></li>
 
<li>'''macosx''': you might need to run <tt>rehash</tt> after <tt>make install</tt> in order to add the <tt>wx-config</tt> utility to the search path cache.</li>
 
<li>'''windows''': sometimes the header file <tt>$wxwin\include\wx\msw\popupwin.h</tt> is not properly copied when <tt>make install</tt> is run, and you need to copy it manually to the install directory (for example <tt>/usr/local/include/wx/msw</tt>). (if this file is not copied, C compilation of wxHaskell will fail).</li></ul>
 
   
 
Now try out a few samples of wxWidgets to see if it all works correctly:
 
Now try out a few samples of wxWidgets to see if it all works correctly:
Line 91: Line 100:
 
=== Building wxHaskell ===
 
=== Building wxHaskell ===
   
  +
Since wxHaskell 0.12.1.1, we only support building using Cabal.
First, we configure the library for your platform.
 
   
  +
For all platforms, provided that wx-config is somewhere in the path and that the WXWIN environment variable points to the root of your wxWidgets installation installation is very straightforward.
<pre>&gt; cd $wxhaskell
 
&gt; ./configure --enable-split-objs --hcprof</pre>
 
Notes:
 
* You can run <tt>configure</tt> first with the <tt>--help</tt> 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 <tt>wx-config</tt> utility is not found – maybe you have forgotten to run <tt>make install</tt> on wxWindows?
 
* You should pass the <tt>--with-opengl</tt> option to <tt>configure</tt> if you specified this flag when configuring wxWidgets (or you will get link errors).
 
* You should pass the <tt>--with-contrib</tt> option to <tt>configure</tt> 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 <tt>user</tt> option: <tt>./configure --user</tt>. And you can specify another directory with the <tt>prefix</tt> option of configure: <tt>./configure --prefix=/usr/local</tt>. Any directory that is on your library search path will do.
 
* '''windows-msc'''. Read the [[WxHaskell/Building_on_Windows|notes]] on building wxHaskell with Visual C++.
 
* If you used the [http://wiki.wxpython.org/InstallingOnUbuntuOrDebian Debian/Ubuntu backport] from [[#Getting_wxWidgets|above]], then you should use both the <tt>--with-opengl</tt> option and the <tt>--with-contrib</tt> option.
 
* If build fails because header files glu.h and several others cannot be found install libglu1-mesa-dev package.
 
   
  +
On Windows platforms, you may also need to set WXCFG=gcc_dll/mswu. You can then install wxhaskell as follows:
After configuration, we build and install the libraries (and take some more time to drink more coffee :-).
 
   
  +
> cabal update
<pre>&gt; make
 
&gt; make install
+
> cabal install wx
&gt; make wx
 
&gt; make wx-install</pre>
 
Notes:
 
<ul>
 
<li>If <tt>make install</tt> 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 [http://www.haskell.org/ghc/docs/latest/html/users_guide/packages.html local ghc package]:
 
<pre>./configure --user</pre>
 
or:
 
<pre>./configure --package-conf=~/mypackages</pre></li>
 
<li>You can generate documentation with <tt>make doc</tt>.</li>
 
<li>The libraries can be uninstalled with <tt>make uninstall</tt>.</li></ul>
 
   
  +
Note that on Unix systems, you may prefer something like
==== building by cabal command ====
 
   
  +
> sudo cabal install --global wx
Cabal doesn't works well currently. This is Cabal and cabal (install)'s problem (e.g. <del>[http://hackage.haskell.org/trac/hackage/ticket/394 394]</del>, [http://hackage.haskell.org/trac/hackage/ticket/431 431]). And current cabal 0.6.0's dependency solver has problem.
 
   
  +
Lazy Windows developers who don't update environment variables can do something like:
So, you should build and install wxHaskell by hand (at least [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/wxcore wxcore] package).
 
   
  +
> WXWIN=/c/path/to/wxWidgets-2.8.10 WXCFG=gcc_dll/mswu cabal install wx
If you want to build and install wxHaskell by cabal command, you must use following command.
 
   
  +
The Windows installation is global by default.
<pre>&gt; cabal install wx --configure-opt="--user --enable-split-objs --hcprof"</pre>
 
  +
  +
=== Source Release ===
  +
  +
You can obtain a source release of wxHaskell from the [http://code.haskell.org/wxhaskell/ darcs repository]. Darcs creates a <tt>wxhaskell</tt> directory for you; we assume in the following example that your <tt>$wxhaskell</tt> directory will be <tt>~/dev/wxhaskell</tt>.
  +
  +
<pre>&gt; cd ~/dev
  +
&gt; darcs get --partial --set-scripts-executable http://code.haskell.org/wxhaskell/</pre>
   
  +
You then build each of the key components in order:
or
 
   
  +
> cd ~/dev/wxhaskell/wxdirect
<pre>&gt; sudo cabal install wxcore --global
 
&gt; cabal install wx</pre>
+
> cabal install
  +
> cd ../wxcore
  +
> cabal install
  +
> cd ../wx
  +
> cabal install
   
 
=== Test wxHaskell ===
 
=== Test wxHaskell ===

Revision as of 00:22, 14 November 2009

For the very lazy

You need to have wxWidgets 2.8.10 installed on your machine (and compiled with MSys g++ if using Windows). Windows users should also get the Windows port of wx-config.

You have correctly configured all of te recommended wxWidgets environment variables, and have a recent version of GHC with an up to date cabal install.

This is all you need:

> cabal install wx

Supported Configurations

The build process has been tested against 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 only with the gnu mingw32 C compiler (windows-mingw).
Please note that we have discontinued support for Microsoft compilers in the build system.

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 :-)

Prerequisites

Ensure you have a recent GHC compiler – version 6.10.3 or higher is recommended. In principle, any Haskell98 compiler that supports the standard FFI libraries along with cabal install should work. We have discontinued support for building without cabal.

  • windows: You will need wx-config for Windows, MinGW 5.1.6 and MSys 0.1.11 (these are the latest versions at the time of writing). You must select the C++ compiler option when installing MinGW.
    • MinGW 5.1.1 can be downloaded from MinGW
    • MSys 0.1.11 can be downloaded from MSys
    • wx-config can be downloaded from wx-config
  • 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.

= You should install the current stable version (2.8.10) of wxWidgets for your platform - versions older than 2.8.1 are no longr supported. Build instructions are given for Windows - on most other platforms you should be able to obtain wxWidgets using your package manager (you may need -developer packages).

We assume in this guide that the variable $wxwin points to your wxWidgets installation directory, for example: ~/dev/wxGTK-2.8.10.

Getting wxWidgets

wxHaskell 0.12.x.x supports wxWidgets > 2.8.

  • Windows:
    • You will need to build using the MinGW compiler - instructions below.
  • 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.

building wxWidgets

On Windows

Note: Microsoft compilers are no longer supported. The cabal build system cannot understand the output of wx-config for Microsoft compilers.

Using the MSys shell, and making sure that you have the C++ compiler oiption installed for MinGW (it is 'not' the default):

> cd /c/path/to/wxWidgets-2.8.10/build/msw
> mingw32-make -f makefile.gcc BUILD=release MONOLITHIC=1 SHARED=1 UNICODE=1

That's it! A DLL is generated in /c/path/to/wxWidgets/gcc_dll, which you will need to copy to a location where it can be found when running your executables.

On Unix systems

You should follow the instructions on the wxWidgets website if there are no suitable packages for your environment. You probably want to use GCC to build wxWidgets, as this makes it more likely that cabal will understand the output of wx-config.

On most Unix platforms, wxWidgets build goes something like: 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

Testing wxWidgets build

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

Since wxHaskell 0.12.1.1, we only support building using Cabal.

For all platforms, provided that wx-config is somewhere in the path and that the WXWIN environment variable points to the root of your wxWidgets installation installation is very straightforward.

On Windows platforms, you may also need to set WXCFG=gcc_dll/mswu. You can then install wxhaskell as follows:

> cabal update
> cabal install wx

Note that on Unix systems, you may prefer something like

> sudo cabal install --global wx

Lazy Windows developers who don't update environment variables can do something like:

> WXWIN=/c/path/to/wxWidgets-2.8.10 WXCFG=gcc_dll/mswu cabal install wx

The Windows installation is global by default.

Source Release

You can obtain a source release of wxHaskell 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/

You then build each of the key components in order:

> cd ~/dev/wxhaskell/wxdirect
> cabal install
> cd ../wxcore
> cabal install
> cd ../wx
> cabal install

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!