Installing SDL on Windows for Haskell (GHC)

百般思念 提交于 2019-12-08 03:08:30
ftl

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

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:

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!