Skip to content

Using haskell gi in Windows

Nicolas Moinard edited this page Feb 22, 2025 · 22 revisions

It is possible to use haskell-gi, and in particular gtk+ programs, in MS Windows. (Note that it is possible to run Windows in a VM for development purposes. Microsoft provides virtual machines here.)

Installing ghc and cabal.

If you are not already using cabal, you will want to install it. To do so, first install

After installing ghcup, open cmd.exe with administrator privileges (for instance, in Windows 10 this can be done by searching in the start menu for the command prompt cmd, right-clicking on the menu entry, and selecting "Run as administrator"). Then in this command prompt run the following commands to install the necessary libraries (this assumes that you installed ghcup under C:\ghcup)

SET PATH=C:\ghcup\msys64\mingw64\bin;C:\ghcup\msys64\usr\bin;%PATH%
SET PKG_CONFIG_PATH=C:\ghcup\msys64\mingw64\lib\pkgconfig
SET XDG_DATA_DIRS=C:\ghcup\msys64\mingw64\share

pacman -S -q --noconfirm git mingw64/mingw-w64-x86_64-pkg-config mingw64/mingw-w64-x86_64-gobject-introspection mingw64/mingw-w64-x86_64-gtksourceview5 mingw64/mingw-w64-x86_64-gtk4 mingw64/mingw-w64-x86_64-atk

The GHcup installer should also install cabal and ghc. If for some reason it doesn't in cmd.exe without administrator priviledges you can run:

ghcup install cabal
ghcup install ghc

It is probably a good idea to make sure that you are using the latest versions of cabal and ghc, use ghcup list to see available versions and ghcup set for setting a version as the default one.

After doing this you should have a working development environment, in which cabal et al will work normally. To compile projects, start cmd.exe again (without administrator privileges), and set the environment variables above before compiling projects:

SET PATH=C:\ghcup\msys64\mingw64\bin;C:\ghcup\msys64\usr\bin;%PATH%
SET PKG_CONFIG_PATH=C:\ghcup\msys64\mingw64\lib\pkgconfig
SET XDG_DATA_DIRS=C:\ghcup\msys64\mingw64\share

cabal build your_project

It might be possible to use the Powershell instead of cmd.exe by setting the environmental variables as described in https://github.com/haskell-gi/haskell-gi/issues/416 .

Powershell examples:

$env:PATH += ";C:\ghcup\msys64\mingw64\bin;C:\ghcup\msys64\usr\bin;%PATH%"
$env:PKG_CONFIG_PATH ="C:\ghcup\msys64\mingw64\lib\pkgconfig"
$env:XDG_DATA_DIRS="C:\ghcup\msys64\mingw64\share"

You kind of have to set the environment variables in a terminal, putting them into "Edit the system environment variables" wouldn't work

If you want the changes to your path to persist in Powershell for the current user:

[Environment]::SetEnvironmentVariable("PKG_CONFIG_PATH", "C:\ghcup\msys64\mingw64\lib\pkgconfig", "User")
[Environment]::SetEnvironmentVariable("XDG_DATA_DIRS", "C:\ghcup\msys64\mingw64\share", "User")
[Environment]::SetEnvironmentVariable("PATH", "$env:PATH;C:\ghcup\msys64\mingw64\bin;C:\ghcup\msys64\usr\bin", "User")

You need to restart your Powershell to apply the changes

Other methods from the official documentation


## How to contribute to this guide

These instructions are definitely not perfect, so if you are a Windows user and think that any part of this guide can be improved, please go ahead and do so! Thanks to Jacek Podkanski for input on the previous version of this guide.

Clone this wiki locally