Difference between revisions of "SDL/Windows"

From HaskellWiki
< SDL
Jump to navigation Jump to search
(Added remark about replacing buggy SDL_platform.h)
(→‎Install and execute SDL2 on a Windows computer: Added a link to "Windows SDL2 is now almost painless via stack")
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
   
== How to install hsSDL2 on a Windows computer ==
+
== Install and execute SDL2 on a Windows computer ==
   
  +
If you want to install SDL2 with [[stack]], see [https://www.reddit.com/r/haskellgamedev/comments/4jpthu/windows_sdl2_is_now_almost_painless_via_stack/ "Windows SDL2 is now almost painless via stack"], otherwise, see below.
Download and [[How to unpack a tar file in Windows | unpack]] the SDL2 development libraries from:
 
  +
  +
Note: when you are using GHC 7.10.2 or earlier, using SDL2 will not be possible; you will get the following message when trying to install a package:
  +
<pre>
  +
<command line>: can't load .so/.DLL for: mingw32.dll (addDLL: could not load DLL)
  +
</pre>
  +
See [https://ghc.haskell.org/trac/ghc/ticket/3242 GHC ticket 3242]
  +
  +
You have to install the C package SDL2 first, then either the Haskell package SDL2 or hsSDL2. See below on how to do this.
  +
  +
=== Downloading files ===
  +
  +
Download the precompiled [https://www.libsdl.org/download-2.0.php SDL2 package] and unzip it to e.g. C:\Libs
  +
  +
=== What architecture to use ===
  +
  +
Open a command prompt and type 'C:\Windows\System32\where.exe ghc.exe'.
  +
'where' will return all ghc.exe files in the %PATH% environment variable.
  +
  +
If your version of GHC is installed in 'C:\Program Files', e.g.
  +
$ where ghc
  +
C:\Program Files\Haskell Platform\7.10.3\bin\ghc.exe
  +
  +
that means you are using a 64 bit version of GHC.
  +
  +
If you also have GCC installed and plan on compiling or linking SDL2 C files in the future, you should probably uninstall 64-bit GHC and install the 32-bit version (Unless you also install(ed) 64-bit GCC).
  +
  +
This because GCC and GHC both hapily accept library files for the wrong architecture, to then error because of invalid linkage. This means you can only have one architecture at a time in the %PATH%. You might be able to get around this restriction with some symlinks, but it's really not worth the effort.
  +
  +
Note that SDL, as many others (including GHC and GCC), use a very confusing naming scheme:
  +
* 32-bit becomes i686-w64-mingw32
  +
* 64-bit becomes x86_64-w64-mingw32
  +
  +
The rest of this page asumes you want to install SDL2-2.0.4 for a 32-bit environment.
  +
  +
=== Compiling from source ===
  +
If you want to compile from source, you will need
  +
* [http://sourceforge.net/projects/pkgconfiglite/files/latest/download pkg-config.exe]
  +
* [http://mingw-w64.org/doku.php Mingw-w64]
  +
* [http://sourceforge.net/projects/mingw/files/MSYS/ MSYS]
  +
  +
If you are using SDL 2.0.3, it is recommended to install [https://hg.libsdl.org/SDL/raw-file/e217ed463f25/include/SDL_platform.h the debugged version of SDL_platform.h] in the include directory.
  +
  +
=== Installing SDL2 ===
  +
  +
Put the following in a install-sdl2.bat file, and execute it as a admin.
  +
SET "SDL_BASEDIR=C:\Libs"
  +
SET "SDL_VERSION=2.0.4"
  +
REM SET "SDL_VERSION=2.0.3"
  +
SET "SDL_ARCH=i686-w64-mingw32"
  +
REM "SDL_ARCH=x86_64-w64-mingw32"
  +
SET "SDL_DIR=%SDL_BASEDIR%\SDL2-%SDL_VERSION%\%SDL_ARCH%"
  +
  +
SETX /M PATH "%SDL_DIR%\bin;%PATH%"
  +
SETX /M LIBRARY_PATH "%SDL_DIR%\bin;C:\Programs\MinGW\lib;%LIBRARY_PATH%"
  +
SETX /M C_INCLUDE_PATH "%LIBRARY_DIR%\include\SDL2;%SDL_DIR%\include;%C_INCLUDE_PATH %"
  +
SETX /M PKG_CONFIG_PATH "%SDL_DIR%\lib\pkgconfig;%PKG_CONFIG_PATH%"
  +
REM SETX /M PKG_CONFIG_PATH "C:\Programs\GTK\lib\pkgconfig\;%PKG_CONFIG_PATH%"
  +
CABAL.EXE install sdl2
  +
  +
Note: You might want make sure all environment variables are correct after installing:
  +
Control Panel -> System and Security -> System -> Advanced system settings -> Environment variables... -> System variables
  +
If the environment variable did not yet exist (as is usually the case with %LIBRARY_PATH%, %C_INCLUDE_PATH% and %PKG_CONFIG_PATH%), the ';%VARIABLE_NAME%' will be included at the end, which might not be desirable (Although it probably won't do any harm).
  +
  +
If no errors are reported, SDL2 is now installed and you should be able to compile, link and execute your programs.
  +
  +
=== Execute your program on other computers ===
  +
  +
In order to ship your SDL2 product, all you will have to do is to include a SDL2.dll from the correct architecture (The one the program is compiled with). You can do this freely by [https://www.libsdl.org/license.php the license of SDL]. By placing the DLL in the same directory as the executable, everything should now run as expected.
  +
  +
== The Haskell package hsSDL2 ==
  +
 
Download and [[How to unpack a tar file in Windows | unpack]] the SDL2 development libraries (the .tar.gz files with mingw in the name) from:
 
* http://www.libsdl.org/download-2.0.php
 
* http://www.libsdl.org/download-2.0.php
 
* http://www.libsdl.org/projects/SDL_image
 
* http://www.libsdl.org/projects/SDL_image
Line 12: Line 84:
 
Set environment variables like this:
 
Set environment variables like this:
 
* To help consistency in the environment variables, we first do:
 
* To help consistency in the environment variables, we first do:
Set LIBRARY_DIR=C:\Libraries
+
SET "LIBRARY_DIR=C:\Libs"
 
* then:
 
* then:
Set PATH=%LIBRARY_DIR%\bin;%PATH%
+
SETX /M PATH "%LIBRARY_DIR%\bin;%PATH%"
Set LIBRARY_PATH=%LIBRARY_DIR%\lib
+
SETX /M LIBRARY_PATH "%LIBRARY_DIR%\lib;%LIBRARY_PATH%"
Set C_INCLUDE_PATH=%LIBRARY_DIR%\include\SDL2;%LIBRARY_DIR%\include
+
SETX /M C_INCLUDE_PATH "%LIBRARY_DIR%\include\SDL2;%LIBRARY_DIR%\include;%C_INCLUDE_PATH%"
   
 
If you don't have [http://git-scm.com/ git] yet, install it.
 
If you don't have [http://git-scm.com/ git] yet, install it.

Latest revision as of 23:58, 17 June 2016

Install and execute SDL2 on a Windows computer

If you want to install SDL2 with stack, see "Windows SDL2 is now almost painless via stack", otherwise, see below.

Note: when you are using GHC 7.10.2 or earlier, using SDL2 will not be possible; you will get the following message when trying to install a package:

<command line>: can't load .so/.DLL for: mingw32.dll (addDLL: could not load DLL)

See GHC ticket 3242

You have to install the C package SDL2 first, then either the Haskell package SDL2 or hsSDL2. See below on how to do this.

Downloading files

Download the precompiled SDL2 package and unzip it to e.g. C:\Libs

What architecture to use

Open a command prompt and type 'C:\Windows\System32\where.exe ghc.exe'. 'where' will return all ghc.exe files in the %PATH% environment variable.

If your version of GHC is installed in 'C:\Program Files', e.g.

$ where ghc
C:\Program Files\Haskell Platform\7.10.3\bin\ghc.exe

that means you are using a 64 bit version of GHC.

If you also have GCC installed and plan on compiling or linking SDL2 C files in the future, you should probably uninstall 64-bit GHC and install the 32-bit version (Unless you also install(ed) 64-bit GCC).

This because GCC and GHC both hapily accept library files for the wrong architecture, to then error because of invalid linkage. This means you can only have one architecture at a time in the %PATH%. You might be able to get around this restriction with some symlinks, but it's really not worth the effort.

Note that SDL, as many others (including GHC and GCC), use a very confusing naming scheme:

  • 32-bit becomes i686-w64-mingw32
  • 64-bit becomes x86_64-w64-mingw32

The rest of this page asumes you want to install SDL2-2.0.4 for a 32-bit environment.

Compiling from source

If you want to compile from source, you will need

If you are using SDL 2.0.3, it is recommended to install the debugged version of SDL_platform.h in the include directory.

Installing SDL2

Put the following in a install-sdl2.bat file, and execute it as a admin.

SET "SDL_BASEDIR=C:\Libs"
SET "SDL_VERSION=2.0.4"
REM SET "SDL_VERSION=2.0.3"
SET "SDL_ARCH=i686-w64-mingw32"
REM "SDL_ARCH=x86_64-w64-mingw32"
SET "SDL_DIR=%SDL_BASEDIR%\SDL2-%SDL_VERSION%\%SDL_ARCH%"

SETX /M PATH "%SDL_DIR%\bin;%PATH%"
SETX /M LIBRARY_PATH "%SDL_DIR%\bin;C:\Programs\MinGW\lib;%LIBRARY_PATH%"
SETX /M C_INCLUDE_PATH "%LIBRARY_DIR%\include\SDL2;%SDL_DIR%\include;%C_INCLUDE_PATH %"
SETX /M PKG_CONFIG_PATH "%SDL_DIR%\lib\pkgconfig;%PKG_CONFIG_PATH%"
REM SETX /M PKG_CONFIG_PATH "C:\Programs\GTK\lib\pkgconfig\;%PKG_CONFIG_PATH%"
CABAL.EXE install sdl2

Note: You might want make sure all environment variables are correct after installing:

 Control Panel -> System and Security -> System -> Advanced system settings -> Environment variables... -> System variables

If the environment variable did not yet exist (as is usually the case with %LIBRARY_PATH%, %C_INCLUDE_PATH% and %PKG_CONFIG_PATH%), the ';%VARIABLE_NAME%' will be included at the end, which might not be desirable (Although it probably won't do any harm).

If no errors are reported, SDL2 is now installed and you should be able to compile, link and execute your programs.

Execute your program on other computers

In order to ship your SDL2 product, all you will have to do is to include a SDL2.dll from the correct architecture (The one the program is compiled with). You can do this freely by the license of SDL. By placing the DLL in the same directory as the executable, everything should now run as expected.

The Haskell package hsSDL2

Download and unpack the SDL2 development libraries (the .tar.gz files with mingw in the name) from:

Copy the bin, lib, include and share directories from the packages to a common directory, like C:\Libraries. If you downloaded SDL 2.0.3, replace the header file include/SDL_platform.h with the debugged version

Set environment variables like this:

  • To help consistency in the environment variables, we first do:
 SET "LIBRARY_DIR=C:\Libs"
  • then:
 SETX /M PATH "%LIBRARY_DIR%\bin;%PATH%"
 SETX /M LIBRARY_PATH "%LIBRARY_DIR%\lib;%LIBRARY_PATH%"
 SETX /M C_INCLUDE_PATH "%LIBRARY_DIR%\include\SDL2;%LIBRARY_DIR%\include;%C_INCLUDE_PATH%"

If you don't have git yet, install it. Go to a directory where you want the Haskell library source code installed and fetch the Haskell libraries:

 git clone https://github.com/Lemmih/hsSDL2
 git clone https://github.com/jdeseno/hs-sdl2-image
 git clone https://github.com/osa1/hsSDL2-ttf
 git clone https://github.com/jdeseno/hs-sdl2-mixer

If you want to use a cabal sandbox:

 cabal sandbox init

Install the Haskell packages:

 cabal install .\hsSDL2
 cabal install .\hs-sdl2-image
 cabal install .\hsSDL2-ttf
 cabal install .\hs-sdl2-mixer


If you get any of the messages:

 cabal: Missing dependency on a foreign library:
 * Missing (or bad) header file: SDL_mixer.h
 configure: error: *** SDL not found! Get SDL from www.libsdl.org.

you should check if all installation steps were done properly.