Skip to content

GHC 9.4+: unused '--unwindlib=libunwind' argument warning when compiling C++ code on Windows

Attempting to compile any project that uses C++ code on GHC 9.4 or later on Windows results in a warning that did not appear in previous versions of Windows. Here is a minimal example:

// hello.cpp
#include <iostream>

extern "C"
void hello() {
  std::cout << "Hello, World!" << std::endl;
}
-- Main.hs
{-# LANGUAGE ForeignFunctionInterface #-}
module Main (main) where

foreign import ccall unsafe "hello" cpp_hello :: IO ()

main :: IO ()
main = cpp_hello

On GHC 9.2.3, this compiles without warnings:

$ ghc-9.2.3 -fforce-recomp Main.hs hello.cpp -lstdc++
[1 of 1] Compiling Main             ( Main.hs, Main.o )
Linking Main.exe ...

On GHC 9.4+, however:

$ ../../../Software/ghc-9.5.20220527/bin/ghc -fforce-recomp Main.hs hello.cpp -lc++ -lc++abi
clang++: warning: argument unused during compilation: '--unwindlib=libunwind' [-Wunused-command-line-argument]
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking Main.exe

Note the '--unwindlib=libunwind' warning, which did not appear previously. This likely arises from this line. I'm unclear if clang++ supports --unwindlib.

Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information