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 3.10.1.0
compiled using version 3.10.1.0 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
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
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-0.1.0.0 (exe:hello-world) (first run)
Configuring executable 'hello-world' for hello-world-0.1.0.0..
Preprocessing executable 'hello-world' for hello-world-0.1.0.0..
Building executable 'hello-world' for hello-world-0.1.0.0..
[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-0.1.0.0\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-0.1.0.0\\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-3.10.1.0.exe: Failed to build exe:hello-world from
hello-world-0.1.0.0.
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.