recent changes to hsc2hs break wrapping c++

Evan Laforge qdunkan at
Wed Feb 15 18:59:54 CET 2012

Recently a change was made to hsc2hs to fix this ticket:

Unfortunately, the result is I (apparently) can't use it now.  Here's
how that happens:  The change was to remove the dependency on HsFFI.h.
 However, the solution is to create a little wrapper .c file that
includes wrappers around various stdio functions like fputs().  This
relies on C allowing implicit casts from void* to e.g. FILE*, and is
also happy to let you use undeclared functions.  g++ rejects that
code.  And since I am calling into C++ (via a 'extern "C" { ... }'
wrapper) I wind up including C++ headers that contain the structs I
want hsc2hs to calculate offsets for.  Of course one solution is to
use C as hsc2hs expects, but it would be awkward to split my (largish)
c++ program's headers into C compatible and C++ only.

So meanwhile I've reverted back to an older version of hsc2hs that
includes HsFFI.h.  Working with c++ headers was maybe not in the
original design for hsc2hs, but it's a very useful feature
nonetheless.  WRT HsFFI.h and the ticket, I added -I(ghc
--print-libdir)/include to my hsc2hs rule a long time ago, and it
wasn't very hard to do, though I admit it would have been easier had
there been documentation about what to do, or a mandatory flag for the
HsFFI.h path.  It looks like Duncan suggested that already.

Or perhaps there's a better way to wrap C++?

More information about the Glasgow-haskell-users mailing list