Building SDL on Windows for use with Haskell / Cabal

If, like me, you wish to perform graphical operations with Haskell you need a library like SDL. Unfortunately most of the Haskell world resides in Linux so it is pretty hard to find good guides for Windows. This guide describes my endeavor to get things working.

I’ll assume that you have nothing installed yet, so you might be able to skip some of these steps.

1. Install the Haskell Platform

You can get it from http://www.haskell.org/platform/ and it will include most of what you will need to work with Haskell on Windows (or any other platform). Installation is as easy as double clicking the installer.

2. Install the MinGW-MSYS tool chain

In order for Cabal (a distribution-manager like apt-get but then just for Haskell) to be able to build packages that have no native Windows libraries we need a Linux like tool chain for Windows.

  • Download the MinGW installer from http://www.mingw.org/wiki/Getting_Started (in the middle of the page there is a blue link to  mingw-get-setup.exe)
  • Run the installer, for legacy reasons install it in a path that does not contain spaces. I’ll asume for now that you’ve installed it in C:\MinGW
  • During the end of the installation a package manager will show. Install the meta package MSYS and click apply changes in the menu.
  • Add C:\MinGW\bin\, C:\MinGW\, and C:\MinGW\msys\1.0\bin\ to the PATH environment variable

3. Install the SDL development libraries

Now we need to install the SDL development libraries and add them to the PATH variable so that the Haskell implementation can link and build.

  • Download the SDL-devel-1.2.15-mingw32.tar.gz archive from http://www.libsdl.org/download-1.2.php and extract. I’ll assume it is located in C:\SDL
  • Add C:\SDL\, and C:\SDL\bin to the PATH environment variable

4. Build Haskell’s SDL implementation

Ok final steps!

  • Open a command prompt
  • Run  cabal install SDL –extra-include-dirs=C:\SDL\include –extra-lib-dirs=C:\SDL\lib
  • This operation should complete with the message ‘Installed SDL-0.6.5′

5. In Conclusion

Building things with Cabal is quite a hassle especially since it uses both the PATH variable and explicitly given paths to find all dependencies, error messages are not to clear either. I hope this guide helps you and saves you some time as it took me two days to get this exactly right. If you wish to see if all really works why not try building and running this little program, it is the reason why I went trough all the steps to get SDL working. (Just left-click and drag to create a rectange, middle click to change the color, and right click to finish the rectangle).

Note: I am aware that the Haskell Platform includes its own version of MinGW but it does not include the MSYS library which is vital under Windows. It is also not easy to modify the built in version of MinGW and according to the docs the build in version can live happily together with the stand alone version.

5 Responses to “Building SDL on Windows for use with Haskell / Cabal”

  1. urs of the backwoods says:

    You might try HBind, described in http://www.hgamer3d.org. It creates bindings which can be compiled on Windows and Linux.But documentation is a little scare in the moment. Also HGamer3D does some graphics.

  2. Hey,

    Thanks for the tip! If I ever need to touch Haskell + 3D again I’ll give it a try.

  3. Andrew says:

    Hello. Thx a lot for this manual – I’ve tryed it and it works! I experimented with anothercompiler – ghc-7.8.2 – and it doesnt compile. Only ghc-7.6.3 works.

    My question is: have you achived any success with building accompanying libraryes like SDL-image, SDL-mixer, and SDL-ttf ?

    If yes, could you share your experience, please.

    Thx.
    Andrew

  4. Hey Andrew,

    Shortly after I got everything working I switched projects. Haven’t used Haskell or SDL since. I haven’t tried to compile the other libraries. Can’t help you there unfortunately.

  5. Giacomo says:

    Hi, thanks for this tutorial. It works well, except for starting SDL programs in ghci / winghci: they comply about missing mingw32.dll and I was’t able to fix it.

Leave a Reply