Personal tools

Windows

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(Shipping Installable Applications: Added WiX Toolset and Zero Install)
(Tools for compilation: Added link to Mingw-w64; mentioned pkg-config.exe)
 
(15 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
== Quickstart on Windows 7 ==
 +
 +
This page describes what you need to know to ''use'' Haskell on a Windows machine.
 +
See [https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation/Windows the GHC Trac Wiki] for what you need to know to ''build'' GHC on Windows.
 +
 +
For a minimal setup [https://www.haskell.org/downloads/windows download the MinGHC package from haskell.org/downloads].
 +
 +
This should install ghc, ghci, cabal, mingw and msys2 to "C:\Program Files\MinGHC-#.##.##" for the latest MinGHC version #, and add the correct programs to your path.
 +
 +
=== Msys2 Shells and Building Hoogle ===
 +
 +
If you launch <hask>msys2_shell.bat</hask> (as opposed to <hask>mingw32_shell.bat</hask> or <hask>mingw64_shell.bat</hask>) then make sure that the following environment variable is defined :
 +
 +
* <hask>MSYSTEM=MINGW32</hask> or <hask>MSYSTEM=MINGW64</hask>
 +
 +
Then test by firing up either <hask>msys2_shell.bat</hask>, <hask>mingw32_shell.bat</hask>, or <hask>mingw64_shell.bat</hask> and then executing the following sequence of commands :
 +
 +
* <hask>
 +
mkdir test
 +
cd test
 +
cabal sandbox init
 +
cabal install hoogle
 +
</hask>
 +
 +
Note that the absence of the environment variables above will result in linker errors when building hoogle.
 +
 
== Editors ==
 
== Editors ==
  
Line 12: Line 38:
 
== Compilers/interpreters ==
 
== Compilers/interpreters ==
  
 +
* [https://www.haskell.org/downloads/windows MinGHC] is a minimal installation of GHC bundled with Cabal.
 
* [http://www.haskell.org/platform/ The Haskell Platform] is a combination of GHC and a set of blessed libraries
 
* [http://www.haskell.org/platform/ The Haskell Platform] is a combination of GHC and a set of blessed libraries
 
* [[WinHugs]]
 
* [[WinHugs]]
Line 19: Line 46:
 
== Tools for compilation ==
 
== Tools for compilation ==
  
* As some of the packages contain Unix/Linux specific scripts/commands, you need [http://www.mingw.org/ MinGW] and [http://www.mingw.org/wiki/msys MSYS] to simulate a Unix environment. In some cases you need [http://www.cygwin.com/ Cygwin] instead.  If you use [http://code.google.com/p/msysgit/ msysgit] on Windows already, all you need to do is add MinGW to your path.
+
If you use [https://www.haskell.org/downloads/windows MinGHC], the necessary compilers and Unix tools for compilation (such as MSYS2, mingw, gcc / g++, etc.) are installed automatically.
 +
 
 +
* As some of the packages contain Unix/Linux specific scripts/commands, you need [http://www.mingw.org/ MinGW] or [http://mingw-w64.org/doku.php Mingw-w64] (the 64 bit version of MinGW) and [http://www.mingw.org/wiki/msys MSYS] to simulate a Unix environment. In some cases you need [http://www.cygwin.com/ Cygwin] instead.  If you use [http://code.google.com/p/msysgit/ msysgit] on Windows already, all you need to do is add MinGW to your path.
  
 
* If you need to link to C-software, [http://en.wikipedia.org/wiki/Environment_variable#DOS.2C_OS.2F2_and_Windows_.28Command_Prompt.29 define environment variable] C_INCLUDE_PATH that lists the directories where the header files can be found, for example:
 
* If you need to link to C-software, [http://en.wikipedia.org/wiki/Environment_variable#DOS.2C_OS.2F2_and_Windows_.28Command_Prompt.29 define environment variable] C_INCLUDE_PATH that lists the directories where the header files can be found, for example:
 
     Set C_INCLUDE_PATH=C:\usr\local\include;C:\usr\local\include\SDL
 
     Set C_INCLUDE_PATH=C:\usr\local\include;C:\usr\local\include\SDL
 
:(It is advisable to use paths without spaces, because some scripts in the MinGW/MSYS environment have problems with spaces in paths.)<br>
 
:(It is advisable to use paths without spaces, because some scripts in the MinGW/MSYS environment have problems with spaces in paths.)<br>
:For linking the libraries you need to define environment variable LIBRARY_PATH as well, listing the directories where .a and .lib files can be found. In case C++ software must be compiled, define CPLUS_INCLUDE_PATH to list the directories with C++ header files.
+
:For linking the libraries, you need to define environment variable LIBRARY_PATH as well, listing the directories where .a and .lib files can be found. In case C++ software must be compiled, define CPLUS_INCLUDE_PATH to list the directories with C++ header files.
 +
 
 +
* Packages are often delivered as a .tar or .tar.gz file, see [[How to unpack a tar file in Windows]]
 +
 
 +
* In some cases, [http://sourceforge.net/projects/pkgconfiglite/files/latest/download pkg-config.exe] is needed for compiling C/C++ packages
 +
 
 +
== Generating Dynamically Linked Libraries (DLL's) ==
 +
 
 +
If you have GHC >= 7.0.1, see [http://www.haskell.org/ghc/docs/latest/html/users_guide/using-shared-libs.html Using shared libraries] and [http://www.haskell.org/ghc/docs/latest/html/users_guide/win32-dlls.html Building and using Win32 DLLs].
 +
 
 +
=== Linking DLL's against C++ ===
 +
 
 +
Recent improvements to GHC's handling of shared libraries make this fairly painless for simple projects. However, as of GHC 7.10.1, linking against C++ object files can break FFI symbol exports. To circumvent the issue, use dlltool.exe (in a similar process to building with < GHC 7.0.1).
 +
 
 +
This process can be automated by combining GHC's ability to generate a makefile, dlltool.exe's ability to create a .def symbol export file from compiled object files, and [http://hackage.haskell.org/package/shake-0.15.4/docs/Development-Shake-Util.html#v:parseMakefile Shake's makefile parser].
 +
 
 +
First the makefile is created:
 +
ghc -M -dep-suffix . dep-makefile ./<make> MyMain.hs
 +
 
 +
Then dlltool.exe extracts all exported symbols from the compiled object files (.o).
 +
 
 +
dlltool.exe -z dll.def -D MyDll.dll --export-all-symbols hs/<file1>.o hs/<file2>.o ...
 +
 
 +
Finally, a .dll can be output by including the .def file in the ghc command.
 +
 
 +
ghc -static -shared -package base -package ... -o MyDll.dll cpp/<file.o> ... hs/<file1>.o hs/<file2>.o ... dll.def -lstdc++
 +
 
 +
dlltool.exe is included in the MinGHC distribution of GHC. In 7.10.1, it is installed at "C:\Program Files\MinGHC-7.10.1\ghc-7.10.1\mingw\bin"
 +
 
 +
A clumsy, but working [http://shakebuild.com/ Shake]file implementing this approach is available [https://gist.github.com/oconnore/7d874f23dc4a825f5bc4 here] for reference.  
  
* Packages are often delivered as a .tar or .tar.gz file, see [[How to unpack a tar file in windows]]
+
=== Building DLL's with an older GHC ===
  
* To work with/produce DLL files with GHC < 7.0.1, you need dlltool.exe, from the [http://sourceforge.net/projects/mingw/files/ mingw-binutils] package and pexports.exe from the [http://sourceforge.net/projects/mingw/files/ mingw-utils] package. For more information see [http://www.cse.yorku.ca/tdb/_doc.php/userg/man/name/dlltool/section/1 the dlltool manual] and [http://www.willus.com/mingw/yongweiwu_stdcall.html Stdcall and DLL tools of MSVC and MinGW]
+
To work with/produce DLL files with GHC < 7.0.1, you need dlltool.exe, from the [http://sourceforge.net/projects/mingw/files/ mingw-binutils] package and pexports.exe from the [http://sourceforge.net/projects/mingw/files/ mingw-utils] package. For more information see [http://www.cse.yorku.ca/tdb/_doc.php/userg/man/name/dlltool/section/1 the dlltool manual] and [http://www.willus.com/mingw/yongweiwu_stdcall.html Stdcall and DLL tools of MSVC and MinGW]
: If you have GHC >= 7.0.1, see [http://www.haskell.org/ghc/docs/latest/html/users_guide/using-shared-libs.html Using shared libraries] or [http://www.haskell.org/ghc/docs/latest/html/users_guide/win32-dlls.html Building and using Win32 DLLs]
+
  
 
== Libraries ==
 
== Libraries ==
Line 37: Line 94:
 
* GUI : [[Gtk2Hs]] - A binding of GTK+ in Haskell. Note: this requires installing [http://www.gtk.org GTK+] on windows.
 
* GUI : [[Gtk2Hs]] - A binding of GTK+ in Haskell. Note: this requires installing [http://www.gtk.org GTK+] on windows.
  
* [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Win32 Win32] - low levelish bindings to Windows API.  Comes with GHC and non-minimal Hugs distribution. [https://github.com/haskell/win32 Win32 darcs repo]
+
* [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Win32 Win32] - low levelish bindings to Windows API.  Comes with GHC and non-minimal Hugs distribution. [https://github.com/haskell/win32 Win32 git repo]
  
 
* [[HDBC-ODBC under Windows]] for database access.
 
* [[HDBC-ODBC under Windows]] for database access.
Line 46: Line 103:
  
 
* If there are DLLs missing from your environment, you can find out which, using [http://cygwin.com/cygwin-ug-net/using-utils.html cygcheck] from the [http://www.cygwin.com/ Cygwin project]. Note, that you will get problems if you have both MinGW and Cygwin in your search path; it is best to specify the full path to cygcheck.exe, or copy cygcheck.exe to some location in the search path.
 
* If there are DLLs missing from your environment, you can find out which, using [http://cygwin.com/cygwin-ug-net/using-utils.html cygcheck] from the [http://www.cygwin.com/ Cygwin project]. Note, that you will get problems if you have both MinGW and Cygwin in your search path; it is best to specify the full path to cygcheck.exe, or copy cygcheck.exe to some location in the search path.
: Another option is [http://www.dependencywalker.com/ Dependency Walker]
+
: Another option is [http://www.dependencywalker.com/ Dependency Walker]; this tool can also be used to find out, in which DLL a crash occurs.
  
 
* [http://www.haskell.org/pipermail/haskell-cafe/2013-February/106436.html Terminal Win32/Building Haskeline/8.3 file issue] (Haskell-cafe)
 
* [http://www.haskell.org/pipermail/haskell-cafe/2013-February/106436.html Terminal Win32/Building Haskeline/8.3 file issue] (Haskell-cafe)
Line 58: Line 115:
 
* GHCi on Cygwin:  When running GHC under a Cygwin shell on Windows, Ctrl-C sometimes doesn't work. A workaround is to use the rlwrap program to invoke GHCi : In addition to proper Ctrl-C, you also get Emacs (or vi) key bindings and command history across sessions, which saves you a load of typing.
 
* GHCi on Cygwin:  When running GHC under a Cygwin shell on Windows, Ctrl-C sometimes doesn't work. A workaround is to use the rlwrap program to invoke GHCi : In addition to proper Ctrl-C, you also get Emacs (or vi) key bindings and command history across sessions, which saves you a load of typing.
  
* If a package depends (either directly or indirectly) on the <code>unix</code> package, you cannot compile it on Windows.
+
* If a package depends (either directly or indirectly) on the <code>unix</code> package, you cannot compile it on Windows (except when using Cygwin).
 
:A simple way to see, if a package X depends on <code>unix</code>, is giving the command:
 
:A simple way to see, if a package X depends on <code>unix</code>, is giving the command:
 
     cabal install X --dry-run
 
     cabal install X --dry-run
Line 81: Line 138:
  
 
* [http://www.haskell.org/platform/windows.html The Haskell Platform] [[Haskell Platform | (HaskellWiki page)]], contains GHC and a set of libraries and tools  
 
* [http://www.haskell.org/platform/windows.html The Haskell Platform] [[Haskell Platform | (HaskellWiki page)]], contains GHC and a set of libraries and tools  
* [http://www.haskell.org/ghc/dist/7.6.3/ghc-7.6.3-i386-unknown-mingw32.tar.bz2 GHC 7.6.3 for Windows x86], [http://www.haskell.org/ghc/dist/7.6.3/ghc-7.6.3-x86_64-unknown-mingw32.tar.bz2 GHC 7.6.3 for Windows 64bit] [[GHC | (HaskellWiki page)]]
+
* [https://www.haskell.org/ghc/dist/7.8.3/ghc-7.8.3-i386-unknown-mingw32.tar.xz GHC 7.8.3 for Windows x86], [https://www.haskell.org/ghc/dist/7.8.3/ghc-7.8.3-x86_64-unknown-mingw32.tar.xz GHC 7.8.3 for Windows 64 bit] [[GHC | (HaskellWiki page)]]
 
* [http://leksah.org/download.html Leksah] [[Leksah | (HaskellWiki page)]]
 
* [http://leksah.org/download.html Leksah] [[Leksah | (HaskellWiki page)]]
 
* [http://darcs.net/Binaries Darcs] [[Darcs | (HaskellWiki page)]]
 
* [http://darcs.net/Binaries Darcs] [[Darcs | (HaskellWiki page)]]
Line 93: Line 150:
 
=== Development ===
 
=== Development ===
  
[ftp://ftp.gnu.org/gnu/non-gnu/cvs/binary/stable/x86-woe/cvs-1-11-22.zip CVS 1.11.22] [http://www.nongnu.org/cvs/ (website)]  ;  [http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi Python 2.4.3] [http://www.python.org/ (website)]  ;  [http://sourceforge.net/projects/scons/files/ Scons] [http://www.scons.org/ (website)]  ;  [http://subversion.tigris.org/files/documents/15/32856/svn-1.3.2-setup.exe SVN 1.3.2] [http://subversion.tigris.org/ (website)]  ;  [http://www.textpad.com/download/ TextPad] [http://www.textpad.com/ (website)]
+
[https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation/Windows Setting up a Windows system for building GHC]
  
 
== Shipping Installable Applications ==
 
== Shipping Installable Applications ==
  
* [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bamse bamse] lets you build windows installers for your Haskell app (MSI).
+
* [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/bamse bamse] lets you build windows installers for your Haskell app (MSI). N.B. <code>bamse</code> is not updated since 2009 and can not be compiled with recent compiler/packages; it depends on <code>com</code>, which also suffered bitrot.
 
* [http://www.jrsoftware.org/isinfo.php Inno Setup] is another tool to create windows installers.
 
* [http://www.jrsoftware.org/isinfo.php Inno Setup] is another tool to create windows installers.
 
* [http://wixtoolset.org/ WiX Toolset], builds Windows installation packages from XML source code
 
* [http://wixtoolset.org/ WiX Toolset], builds Windows installation packages from XML source code

Latest revision as of 10:04, 8 December 2015

Contents

[edit] 1 Quickstart on Windows 7

This page describes what you need to know to use Haskell on a Windows machine. See the GHC Trac Wiki for what you need to know to build GHC on Windows.

For a minimal setup download the MinGHC package from haskell.org/downloads.

This should install ghc, ghci, cabal, mingw and msys2 to "C:\Program Files\MinGHC-#.##.##" for the latest MinGHC version #, and add the correct programs to your path.

[edit] 1.1 Msys2 Shells and Building Hoogle

If you launch
msys2_shell.bat
(as opposed to
mingw32_shell.bat
or
mingw64_shell.bat
) then make sure that the following environment variable is defined :
  • MSYSTEM=MINGW32
    or
    MSYSTEM=MINGW64
Then test by firing up either
msys2_shell.bat
,
mingw32_shell.bat
, or
mingw64_shell.bat
and then executing the following sequence of commands :
  • mkdir test
    cd test
    cabal sandbox init
    cabal install hoogle

Note that the absence of the environment variables above will result in linker errors when building hoogle.

[edit] 2 Editors

[edit] 3 Compilers/interpreters

  • MinGHC is a minimal installation of GHC bundled with Cabal.
  • The Haskell Platform is a combination of GHC and a set of blessed libraries
  • WinHugs
  • GHC: Special notes for Cygwin users - [1] [2]
  • WinGhci, a GUI for GHCi (included in the Haskell Platform)

[edit] 4 Tools for compilation

If you use MinGHC, the necessary compilers and Unix tools for compilation (such as MSYS2, mingw, gcc / g++, etc.) are installed automatically.

  • As some of the packages contain Unix/Linux specific scripts/commands, you need MinGW or Mingw-w64 (the 64 bit version of MinGW) and MSYS to simulate a Unix environment. In some cases you need Cygwin instead. If you use msysgit on Windows already, all you need to do is add MinGW to your path.
  • If you need to link to C-software, define environment variable C_INCLUDE_PATH that lists the directories where the header files can be found, for example:
    Set C_INCLUDE_PATH=C:\usr\local\include;C:\usr\local\include\SDL
(It is advisable to use paths without spaces, because some scripts in the MinGW/MSYS environment have problems with spaces in paths.)
For linking the libraries, you need to define environment variable LIBRARY_PATH as well, listing the directories where .a and .lib files can be found. In case C++ software must be compiled, define CPLUS_INCLUDE_PATH to list the directories with C++ header files.
  • In some cases, pkg-config.exe is needed for compiling C/C++ packages

[edit] 5 Generating Dynamically Linked Libraries (DLL's)

If you have GHC >= 7.0.1, see Using shared libraries and Building and using Win32 DLLs.

[edit] 5.1 Linking DLL's against C++

Recent improvements to GHC's handling of shared libraries make this fairly painless for simple projects. However, as of GHC 7.10.1, linking against C++ object files can break FFI symbol exports. To circumvent the issue, use dlltool.exe (in a similar process to building with < GHC 7.0.1).

This process can be automated by combining GHC's ability to generate a makefile, dlltool.exe's ability to create a .def symbol export file from compiled object files, and Shake's makefile parser.

First the makefile is created:

ghc -M -dep-suffix . dep-makefile ./<make> MyMain.hs

Then dlltool.exe extracts all exported symbols from the compiled object files (.o).

dlltool.exe -z dll.def -D MyDll.dll --export-all-symbols hs/<file1>.o hs/<file2>.o ...

Finally, a .dll can be output by including the .def file in the ghc command.

ghc -static -shared -package base -package ... -o MyDll.dll cpp/<file.o> ... hs/<file1>.o hs/<file2>.o ... dll.def -lstdc++

dlltool.exe is included in the MinGHC distribution of GHC. In 7.10.1, it is installed at "C:\Program Files\MinGHC-7.10.1\ghc-7.10.1\mingw\bin"

A clumsy, but working Shakefile implementing this approach is available here for reference.

[edit] 5.2 Building DLL's with an older GHC

To work with/produce DLL files with GHC < 7.0.1, you need dlltool.exe, from the mingw-binutils package and pexports.exe from the mingw-utils package. For more information see the dlltool manual and Stdcall and DLL tools of MSVC and MinGW

[edit] 6 Libraries

  • GUI : Gtk2Hs - A binding of GTK+ in Haskell. Note: this requires installing GTK+ on windows.
  • Win32 - low levelish bindings to Windows API. Comes with GHC and non-minimal Hugs distribution. Win32 git repo
  • winerror: Error handling for foreign calls to the Windows API

[edit] 7 Special tips and tricks for Windows

  • If there are DLLs missing from your environment, you can find out which, using cygcheck from the Cygwin project. Note, that you will get problems if you have both MinGW and Cygwin in your search path; it is best to specify the full path to cygcheck.exe, or copy cygcheck.exe to some location in the search path.
Another option is Dependency Walker; this tool can also be used to find out, in which DLL a crash occurs.
  • Instead of using WinGHCi, one can also run GHCi in shell mode in Emacs — do 'M-x shell' in Emacs, then type 'ghci'.
  • GHCi on Cygwin: When running GHC under a Cygwin shell on Windows, Ctrl-C sometimes doesn't work. A workaround is to use the rlwrap program to invoke GHCi : In addition to proper Ctrl-C, you also get Emacs (or vi) key bindings and command history across sessions, which saves you a load of typing.
  • If a package depends (either directly or indirectly) on the unix package, you cannot compile it on Windows (except when using Cygwin).
A simple way to see, if a package X depends on unix, is giving the command:
   cabal install X --dry-run
This will list all packages that would be installed
  • If you are missing or need to distribute libraries with an application, the correct place to put them is *NOT* in \WINDOWS\System32 as once was the practice in the early days of Windows. All sane applications/installers keep their own private dependencies in the application directory. E.g., if the user has chosen to install your application to C:\Program Files\Foo then it is best to install any DLLs in the same location.
  • When compiling a program with GUI, use the compiler option -optl-mwindows to prevent a DOS-shell being displayed behind your GUI. (This passes the option -mwindows to the linker.)
  • Source files from Unix(-like) systems have lines terminated with Line Feed only; if your favorite editor cannot handle this, you can convert the files to MS-DOS format with the unix2dos command (from the mingw-utils package). For more information, give command: unix2dos --help
Note, that GHC can handle source files in Unix format.
  • To convert a set of files to MS-DOS format (note: this might damage binary files):
C:\MSYS\1.0\bin\find . -type f -exec unix2dos {} ;
Note: the find command included in MSYS is different from the MS-DOS find command, therefore, you need to specify the entire path to this command.

[edit] 8 Binary downloads

[edit] 8.1 Haskell

Below a list of binary packages for Windows. To be sure you get the most recent version of each, it is best to download the source from Hackage and compile (except for the Haskell Platform).

[edit] 8.2 Development

Setting up a Windows system for building GHC

[edit] 9 Shipping Installable Applications

  • bamse lets you build windows installers for your Haskell app (MSI). N.B. bamse is not updated since 2009 and can not be compiled with recent compiler/packages; it depends on com, which also suffered bitrot.
  • Inno Setup is another tool to create windows installers.
  • WiX Toolset, builds Windows installation packages from XML source code
  • Zero Install creates packages for several platforms ("a decentralised cross-distribution software installation system")