Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,869
    • Issues 4,869
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #21435
Closed
Open
Created Apr 26, 2022 by Ryan Scott@RyanGlScottMaintainer

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:

  1. Grab a nightly Windows bindist. I'm using a bindist at commit f2c08124.

  2. Grab a nightly Windows build of cabal-install. I'm using the one here.

  3. 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
  4. Using the HEAD versions of cabal-install and GHC, build text 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
  5. 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.

  6. 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 to text.cabal makes no difference.

  • I did not have mingw-w64-x86_64-libc++ or mingw-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 include 89feee7, 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.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking