Can't link against libc++ with HEAD on Windows
Now that HEAD uses Clang/lld
as its C toolchain, I decided to try it out on some code that links against the C++ standard library. Unfortunately, I wasn't able to get very far. In fact, I wasn't even able to get the text
library to build after https://github.com/haskell/text/pull/429.
To reproduce:
-
Grab a nightly Windows bindist. I'm using a bindist at commit f2c08124.
-
Grab a nightly Windows build of
cabal-install
. I'm using the one here. -
Clone the https://github.com/haskell/text repo and check out commit
89feee7
:$ git clone https://github.com/haskell/text && cd text/ $ git reset --hard 89feee7e8a3b7e55dc8544cd21ea5f908cc8aea9
-
Using the HEAD versions of
cabal-install
and GHC, buildtext
and write a GHC environment file:$ <path-to-cabal>/cabal.exe build -w <path-to-ghc>/ghc-9.3.20220425/bin/ghc --allow-newer --write-ghc-environment-files=always --keep-going
-
Try compiling the following example program in the same directory and running it:
module Main where import Data.Text main :: IO () main = print $ pack "Hello, World!"
$ $USERPROFILE/Software/ghc-9.3.20220425/bin/ghc Main.hs Loaded package environment from C:\Users\winferno\Documents\Hacking\Haskell\text\.ghc.environment.x86_64-mingw32-9.3.20220425 [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking Main.exe $ ./Main.exe C:/Users/winferno/Documents/Hacking/Haskell/text/Main.exe: error while loading shared libraries: libc++.dll: cannot open shared object file: No such file or directory
As this demonstrates, loading fails before the program can be run.
-
A similar failure can be observed when loading the program into GHCi:
$ $USERPROFILE/Software/ghc-9.3.20220425/bin/ghci Main.hs WARNING: GHCi invoked via 'ghci.exe' in MinTTY consoles (e.g., Cygwin or MSYS) doesn't handle Ctrl-C well; use the 'ghcii.sh' shell wrapper instead Loaded package environment from C:\Users\winferno\Documents\Hacking\Haskell\text\.ghc.environment.x86_64-mingw32-9.3.20220425 GHCi, version 9.3.20220425: https://www.haskell.org/ghc/ :? for help ghc-9.3.20220425.exe: Could not load `libc++.dll'. Reason: addDLL: libc++.dll or dependencies not loaded. (Win32 error 126) Loaded GHCi configuration from C:\Users\winferno\AppData\Roaming\ghc\ghci.conf Ok, one module loaded. > main ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `_ZNSt3__119__libcpp_mutex_lockEPPv' ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `_ZN10__cxxabiv130__aligned_malloc_with_fallbackEy' ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `__cxa_begin_catch' ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `_ZSt15get_new_handlerv' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\dist-newstyle\build\x86_64-windows\ghc-9.3.20220425\text-2.0\build\libHStext-2.0-inplace.a: unknown symbol `_ZdlPv' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\dist-newstyle\build\x86_64-windows\ghc-9.3.20220425\text-2.0\build\libHStext-2.0-inplace.a: unknown symbol `_ZN7simdutf13validate_utf8EPKcy' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\dist-newstyle\build\x86_64-windows\ghc-9.3.20220425\text-2.0\build\libHStext-2.0-inplace.a: unknown symbol `_hs_text_is_valid_utf8' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\dist-newstyle\build\x86_64-windows\ghc-9.3.20220425\text-2.0\build\libHStext-2.0-inplace.a: unknown symbol `textzm2zi0zminplace_DataziTextziEncoding_zdwdecodeUtf8With_info' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\Main.o: unknown symbol `textzm2zi0zminplace_DataziText_pack_closure' ghc-9.3.20220425.exe: Could not load Object Code C:\Users\winferno\Documents\Hacking\Haskell\text\Main.o.
Some further observations:
-
One hypothesis for why this is failing is because
text
is trying to link against dynamic libraries in this line in its.cabal
file:extra-libraries: c++ c++abi
If I change it in an effort to force GHC to link against the static versions of these libraries:
extra-libraries: :libc++.a :libc++abi.a
Then I am able to compile the example program and run it with
./Main.exe
. However, I am still unable to run it with GHCi:$ <path-to-ghc>/ghc-9.3.20220425/bin/ghci Main.hs WARNING: GHCi invoked via 'ghci.exe' in MinTTY consoles (e.g., Cygwin or MSYS) doesn't handle Ctrl-C well; use the 'ghcii.sh' shell wrapper instead Loaded package environment from C:\Users\winferno\Documents\Hacking\Haskell\text\.ghc.environment.x86_64-mingw32-9.3.20220425 GHCi, version 9.3.20220425: https://www.haskell.org/ghc/ :? for help <command line>: addDLL: :libc++.a or dependencies not loaded. (Win32 error 126)
-
Adding
ghc-options: -static
totext.cabal
makes no difference. -
I did not have
mingw-w64-x86_64-libc++
ormingw-w64-x86_64-libc++abi
installed in the steps above. If I install them and then repeat the steps above, then I am able to compile the example program and run it with./Main.exe
. However, I am still unable to run it with GHCi:$ $USERPROFILE/Software/ghc-9.3.20220425/bin/ghci Main.hs WARNING: GHCi invoked via 'ghci.exe' in MinTTY consoles (e.g., Cygwin or MSYS) doesn't handle Ctrl-C well; use the 'ghcii.sh' shell wrapper instead Loaded package environment from C:\Users\winferno\Documents\Hacking\Haskell\text\.ghc.environment.x86_64-mingw32-9.3.20220425 GHCi, version 9.3.20220425: https://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from C:\Users\winferno\AppData\Roaming\ghc\ghci.conf Ok, one module loaded. > main ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `_ZdlPv' ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `_ZTISt13bad_exception' ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `__gxx_personality_seh0' ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `_ZN10__cxxabiv130__aligned_malloc_with_fallbackEy' ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `__cxa_begin_catch' ghc-9.3.20220425.exe: | C:\Users\winferno\Software\ghc-9.3.20220425\mingw\lib\libc++abi.a: unknown symbol `_ZSt15get_new_handlerv' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\dist-newstyle\build\x86_64-windows\ghc-9.3.20220425\text-2.0\build\libHStext-2.0-inplace.a: unknown symbol `_ZdlPv' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\dist-newstyle\build\x86_64-windows\ghc-9.3.20220425\text-2.0\build\libHStext-2.0-inplace.a: unknown symbol `_ZN7simdutf13validate_utf8EPKcy' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\dist-newstyle\build\x86_64-windows\ghc-9.3.20220425\text-2.0\build\libHStext-2.0-inplace.a: unknown symbol `_hs_text_is_valid_utf8' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\dist-newstyle\build\x86_64-windows\ghc-9.3.20220425\text-2.0\build\libHStext-2.0-inplace.a: unknown symbol `textzm2zi0zminplace_DataziTextziEncoding_zdwdecodeUtf8With_info' ghc-9.3.20220425.exe: | C:\Users\winferno\Documents\Hacking\Haskell\text\Main.o: unknown symbol `textzm2zi0zminplace_DataziText_pack_closure' ghc-9.3.20220425.exe: Could not load Object Code C:\Users\winferno\Documents\Hacking\Haskell\text\Main.o.
-
Somehow, the Windows CI on this MR, which bumps the
text
submodule to include89feee7
, compiles and passes the test suite without issue (example). I wonder if there is some configuration difference between the Windows CI runner and my own local machine.