[SOLVED] GHC on Windows fails with "undefined reference to mingw_app_type", etc

I installed GHC on Windows 11 yesterday, via ghcup:

$ uname -a
MINGW64_NT-10.0-22621 couch-potato 3.4.9.x86_64 2023-09-15 12:15 UTC x86_64 Msys
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.2.8
$ cabal --version
cabal-install version
compiled using version of the Cabal library
$ gcc --version
gcc.exe (Rev2, Built by MSYS2 project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

Today, I tried using GHC. I tried building a simple “Hello, World!” program (the default program created by cabal init). However, it fails with linker errors:

$ cabal-build
Resolving dependencies...
Build profile: -w ghc-9.2.8 -O1
In order, the following will be built (use -v for more details):
 - hello-world- (exe:hello-world) (first run)
Configuring executable 'hello-world' for hello-world-
Preprocessing executable 'hello-world' for hello-world-
Building executable 'hello-world' for hello-world-
[1 of 1] Compiling Main             ( src-exe\Main.hs, C:\\Users\ppelleti\prg\hs\hello\dist-newstyle\build\x86_64-windows\ghc-9.2.8\hello-world-\x\hello-world\build\hello-world\hello-world-tmp\Main.o )
Linking C:\\Users\\ppelleti\\prg\\hs\\hello\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.8\\hello-world-\\x\\hello-world\\build\\hello-world\\hello-world.exe ...
C://ghcup//ghc//9.2.8//mingw//bin/ld.exe: C://ghcup//ghc//9.2.8//mingw//bin/../x86_64-w64-mingw32/lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_app_type[.refptr.mingw_app_type]+0x0): undefined reference to `mingw_app_type'
C://ghcup//ghc//9.2.8//mingw//bin/ld.exe: C://ghcup//ghc//9.2.8//mingw//bin/../x86_64-w64-mingw32/lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initcharmax[.refptr.mingw_initcharmax]+0x0): undefined reference to `mingw_initcharmax'
C://ghcup//ghc//9.2.8//mingw//bin/ld.exe: C://ghcup//ghc//9.2.8//mingw//bin/../x86_64-w64-mingw32/lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltssuo_force[.refptr.mingw_initltssuo_force]+0x0): undefined reference to `mingw_initltssuo_force'
C://ghcup//ghc//9.2.8//mingw//bin/ld.exe: C://ghcup//ghc//9.2.8//mingw//bin/../x86_64-w64-mingw32/lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltsdyn_force[.refptr.mingw_initltsdyn_force]+0x0): undefined reference to `mingw_initltsdyn_force'
C://ghcup//ghc//9.2.8//mingw//bin/ld.exe: C://ghcup//ghc//9.2.8//mingw//bin/../x86_64-w64-mingw32/lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltsdrot_force[.refptr.mingw_initltsdrot_force]+0x0): undefined reference to `mingw_initltsdrot_force'
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
Error: cabal- Failed to build exe:hello-world from

Any idea what causes these and how to fix them?

Searching online reveals that other people are also getting this error (not with Haskell, but with other languages like C++ and Rust). However, none of the pages I’ve looked at so far give a clear explanation of what’s wrong and how to fix it.

1 Like

This may not be of use to you, as it does not go directly to your question, and you may well want to stay with GHCup and Cabal (the tool), but as a Windows 11 user, I have had no problems with Stack and GHC 9.2.8. You can use Stack directly in PowerShell (you don’t need to use a MSYS2 environment).

To use GHC 9.2.8, you would specify resolver: lts-20.26 in Stack’s project-level configuration file (stack.yaml).


I have no particular attachment to GHC 9.2.8. That’s just what I got by following the installation instructions. (I think because 9.2.8 is marked as “recommended”.)

I wonder if a newer version of GHC would have any better chance of working than the “recommended” version? I’m attempting to install 9.6.3 now. (Although I’m having trouble getting it to download successfully.)

I’ve used stack in the past, but I got the impression it’s not being maintained as actively anymore. I might try it if I get too frustrated with ghcup. (Everyone says ghcup is the recommended way to install GHC now, so I thought I should try it. So far, I’m not impressed.)

I’m much more comfortable working in MSYS2/bash. I don’t know anything about PowerShell.

Edit: I succeeded in installing GHC 9.6.3, and it worked fine without any problems. So apparently ghcup “recommends” a version of GHC that doesn’t work!

What msys2 version are you using?

How do I find that out?

I think you were experiencing this GHC bug #21111: [windows] GHC fails to link due to msys2 crt update · Issues · Glasgow Haskell Compiler / GHC · GitLab, fixed in later versions of GHC. EDIT: as a Windows user, you are best advised to use GHC >= 9.4 because of that bug. (I had forgotten it, because it did not affect the Stack-supplied version of MSYS2.)


To follow up on a few other points:

  • GHCup is, in my view, an excellent tool, and an essential one if you are using Cabal (the tool) or the Haskell extension for the popular Visual Studio Code editor - because Cabal does not aim to be an ‘installer’ (Stack is more of a ‘penknife’; it has more than one blade). I would recommend that you don’t let this GHC bug put you off it.
  • The GHCup project weighs up various factors before deciding to bump its GHC recommendation. This discussion gives an insight into that: [RFC] Bumping recommended GHC to 9.4.5 in GHCup.
  • Stack is being actively looked after and, I hope, will be developed further - but that activity does depend on volunteers. See Code frequency · commercialhaskell/stack · GitHub
  • If you much prefer MSYS2/bash, and your machine has enough disk space for two operating systems, you might want to explore also Haskell on Linux on Windows Subsystem for Linux 2 (WSL2).

I do most of my development on my Linux host machine. The reason I installed Haskell in the Windows VM was to check if my package builds succesfully on Windows. (I have a bit of platform-specific code that uses the unix and Win32 packages, and up until now I’ve been writing the Win32 part blind.)

1 Like

We have just updated the recommended GHC version to 9.4.7: Bump recommended GHC to 9.4.7 by hasufell · Pull Request #138 · haskell/ghcup-metadata · GitHub