2

Background:

I've been using the gloss library for some simple diagram work. But when it came time for something more interactive, I found I wanted a more powerful library. After doing some research, I decided that I liked the features of the SDL library and wanted to try to install the Haskell bindings for it. I have to this point been unsuccessful.

Part 1:

How do I install and configure the SDL binaries so that they can be used by the Haskell bindings?

Part 2:

Which one of the numerous and ill documented SDL packages on Hackage it the current preferred binding in the community? How do I get that package to install correctly?

Part 3: (Optional)

If SDL is not a good fit for haskell development what is the preferred alternative?

6
  • What OS are you running?
    – Mokosha
    Sep 3, 2014 at 3:12
  • 1
    @Mokosha Title mentions Windows. Sep 3, 2014 at 4:49
  • I want to address Part 3: SDL and Haskell go together wonderfully, but if you truly want to leverage the power of Haskell, both as a functional language, and the beautiful and amazing language that it is, in GUI applications: use FRP (Functional Reactive Programming). In terms of practice, I recommend either reactive-banana or sodium - they're almost identical (which is amusing, since it was never the intention and just happened to be so). Sep 3, 2014 at 4:54
  • I am running Windows 7. Sep 3, 2014 at 5:34
  • Do you want to experiment or really produce something? The reason I ask is that it's a major pain to get this running on windows and it's far easier to install a Linux VM and experiment with Haskell/SDL in there
    – Random Dev
    Sep 3, 2014 at 7:02

2 Answers 2

5

I am going to answer your question for SDL2 (should also work for SDL1 with some modifications).

  1. Install pkg-config for Windows (How to install pkg config in windows?)

    This tool is very important. It is used by various Cabal packages to search for libraries and contains directions for linking and compiling.

  2. Download the SDL development libraries for Windows/MinGW: http://libsdl.org/release/SDL2-devel-2.0.3-mingw.tar.gz

    If you have installed the 32-bit version of the Haskell platform, extract the folder i686-w64-mingw32

    For 64-bit versions extract x86_64-w64-mingw32

    You will get following layout:

    include
    share
    bin
    lib

  3. "Register" the library with pkg-config.

    Either copy lib/pkgconfig/sdl2.pc into the folder of your pkg-config.exe or modify/create the PKG_CONFIG_PATH accordingly. Check that you set up everything correctly:

    C:\pkg-config --list-all | grep sdl2

    sdl2 sdl2 - Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.

  4. Add the bin folder to your PATH environment variable.

  5. Install the sdl2 package via the Cabal installer and tell Cabal where to find your libraries.

    Example: cabal install sdl2 --extra-include-dirs=C:\lib\sdl2\include --extra-lib-dirs=C:\lib\sdl2\lib\

To test my installation, I have written a small example:

https://github.com/ftl2014/haskell-stuff/blob/master/sdl/

Caveat emptor:

If Cabal complains about a "missing" library, it might be the case that library was actually found but it is incompatible (e.g. using a 32-bit instead of a 64-bit version) or corrupt. The same is true for header files. For some reason, Cabal complained about not finding SDL.h, and I had to use the headers in the root include folder of the archive (but maybe I was just drinking too much Kool-aid).

1

I wasn't able to get it to install on my system. Here's what I tried. Strangely, I was able to get configure find the header files but not the actual binary.

Let's try it. I have installed the new 2014 Haskell Platform.

cabal install sdl

Configuring SDL-0.6.5...
setup.exe: The package has a './configure' script. This requires a Unix
compatibility toolchain such as MinGW+MSYS or Cygwin.
Failed to install SDL-0.6.5

GHC in the Haskell Platform comes with MinGW, so we probably need to install MSYS. The MSYS page says to install minggw get, which says to install

An automated GUI installer assistant called mingw-get-setup.exe is the preferred method for first time installation. This will guide you through the setup of the mingw-get installer proper; you will then use this to perform further package installations, and to manage your installation.

Running the installer with the default options gives us the following screen:

mingw-get GUI

We already have mingw from installing the Haskell platform, so we'll click on only the last item in the list, msys-base, and select "Mark for Installation". Then, in the "Installation" menu in the top left, select "Apply Changes". This asks if it is ok to proceed, and we select "Apply"

This installer didn't put msys-base in the path, we can add it to the path, and try installing sdl again

set PATH=C:\MinGW\msys\1.0\bin\;%PATH%
cabal install sdl

Configuring SDL-0.6.5...
configure: WARNING: unrecognized options: --with-compiler, --with-gcc
checking for sdl-config... no
checking for sdl11-config... no
configure: error: *** SDL not found! Get SDL from www.libsdl.org.
If you already installed it, check it's in the path. If problem remains,
please send a mail to the address that appears in ./configure --version
indicating your platform, the version of configure script and the problem.
Failed to install SDL-0.6.5

We need to download and install libsdl. I went to the libsdl download page and downloaded the Win32 development libraries, SDL-devel-1.2.15-mingw32.tar.gz. I extracted this archive (7-zip can extract both tar archives and gzip compressed files). For convenience, I moved the SDL-1.2.15 directory to c:. We'll add this to the path, as suggested by the previous error, and try again

set PATH=C:\SDL-1.2.15\bin\;%PATH%
cabal install sdl

* Missing (or bad) header file: SDL/SDL.h
* Missing C library: SDL
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
If the header file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.

We can make part of this error go away by adding the suggested --extra-include-dirs flag, but still get the following error

cabal install sdl --extra-include-dirs=c:\SDL-1.2.15\include

* Missing C library: SDL
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.

Adding the --extra-lib-dirs flag with c:\SDL-1.2.15\bin or C:\SDL-1.2.15\lib or c:\SDL-1.2.15 failed to fix this problem.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.