[Haskell-cafe] Wrapping a C++ library

Donn Cave donn at avvanta.com
Mon Jan 26 22:37:03 UTC 2015


Quoth Arjun Comar <nrujac at gmail.com>,
> Richard,
> If you create a straight C header that's able to call into the C++ library
> then what you're trying to do will work. This is the standard (though
> frustrating) approach to using C++ libraries within Haskell. I can send you
> an example cabal file for building the Haskell code against the C headers
> and archives if you'd like. There isn't much more to it than what you're
> already doing though. The key is that the headers have to be pure C and you
> have to force cabal to build the C code with g++ (since the implementing .c
> files will necessarily make C++ calls).

This is probably an absurdly elementary question, but at this last point,
"... force cabal to build the C code with g++ ...", wouldn't this happen
automatically, since they'll really be .C, not .c, files?

E.g., in

   Blegger.hsc       (#include "blegger.h")
   Blegger_stub.c    (C code created by hsc2hs)
   blegger.h         (C include file)
   blegger.C         (extern "C" { #include "blegger.h" })

... _stub.c shouldn't need g++, and .C should get it naturally?

	Donn


More information about the Haskell-Cafe mailing list