Haskell SDL Bindings on Windows

I recently wanted to get the Haskell SDK bindings running on windows. It was a bit trickier than I thought it would be — mostly due to a terrible macro SDL used to redefine the main() function. I used the SDL 1.2 bindings as they’re a little more mature than the SDL 2 bindings, which are pretty much brand new. Here is how I got things working:

1. Install the Haskell Platform

Download and run the installer from the Haskell website.

2. Get the msys Base Environment

Download mingw-get-setup.exe from the MinGW website and run it. You should only have to select the msys-base meta-package (which will install several other packages). Then from the menu, select “Installation” -> “Apply Changes” and press the “Apply” button to download and install. Once the changes are applied, you can close the installer.

Take a note of the install path, it’s usually C:\MinGW unless you change it. We’ll call this the mingw-install-path (even though we’re only installing msys).

3. Get SDL Development Libraries

Download the SDL-1.2 Win32 mingw32 development libraries from the SDL website (they’re usually at the bottom). Extract them to some directory. We’ll call this the SDL-install-path

In the extracted directory there should be a file: bin/sdl_config. Open it in a text editor. There should be a: prefix=/usr/local/cross-tools/i686-w64-mingw32. Replace it with your SDL-install-path, but make sure you replace all the backslashes in the path with for slashes, and remove the colons. So if your SDL-install-path was:
C:\Developer\SDL-1.2.15 you’d put /c/Developer/SDL-1.2.15.

If your SDL-install-path has spaces in it, you lose two nerd points and should go move it to a path without spaces.

Then, add the directory containing sdl_config to your path, and add SDL-install-path\lib to your path.

4. Install SDL Haskell Bindings

Run: mingw-install-path\msys\1.0\msys.bat, (which will probably be: C:\MinGW\msys\1.0\msys.bat). This should open a shell window.

In the shell window, type: cabal update. If this is a fresh Haskell platform install you’ll probably be prompted to update cabal-install. DON’T.

Then type: cabal install sdl —-extra-include-dirs=SDL-install-path/include —-extra-lib-dirs=SDL-install-path/lib. For example: cabal install sdl —-extra-include-dirs=/c/Developer/SDL-1.2.15/include —-extra-lib-dirs=/c/Developer/SDL-1.2.15/lib.

5. Get SDL_Image Development Libraries

Download SDLimage windows development libraries here: libsdl.org/projects/SDLimage/release-1.2.html. They’ll be named something like: SDL_image-devel-1.2.12-VC.zip.

Extract it to a directory. We’ll refer to this directory as SDL_image-install-path

Take SDL_Image.h from SDL_image-install-path/include and copy it to SDL-install-path/include/SDL. Then take everything in SDL_image-install-path/lib/x86 and copy it to SDL-install-path/lib. Note the x86 in the above path, don’t copy the wrong one.

Once we get everything working, you can delete the SDL_image-install-path as we’ve copied everything we need out of it.

6. Installing SDL-image Haskell Bindings

In a directory of your choice (but from the msys shell) do a cabal unpack SDL-image. This will download and unpack the SDL-image package from hackage.

Open SDL-image-0.6.1\Graphics\UI\SDL\Image\Version.hsc in an editor. Underneath #include “SDL_image.h” add:

#ifdef main  
#undef main  
#endif  

From the msys shell cd into the unpacked SDL-image directory and run: cabal install --extra-include-dirs=/c/Developer/SDL-1.2.15/include/SDL --extra-lib-dirs=/c/Developer/SDL-1.2.15/lib. (Note that this is slightly different command from the SDL cabal install, though it looks similar.)

7. Building a Template SDL Haskell Project

Now if you want, you can switch back to a normal windows cmd shell. In a directory of your choosing do a git clone https://github.com/Manticore/haskell-sdl-template. Then cd into that directory and do:

  • cabal install –only-dependencies
  • cabal configure
  • cabal build

Copy image.png to dist\build\Resources (you’ll have to create the Resources dir), and run dist\build\sdltemplate\sdltemplate.exe.

Ta da!

Conversation
  • Mickael says:

    Thank you so much! After spending literally close to 12 hours over two days trying to install either the OpenAL package of the SDL package, the steps you are providing finally did the trick.

    • Job Vranish Job Vranish says:

      Yay! I’m glad somebody got some use out of it :)
      It was definitely a non-trivial amount of effort to get it working :)

  • Comments are closed.