[Haskell-cafe] Wrapping a C++ library

Arjun Comar nrujac at gmail.com
Mon Jan 26 22:46:32 UTC 2015


Unfortunately, Cabal doesn't support C++ sources directly. So if you plan
to use make or something to build the .C files outside of cabal, you're
right. But if you plan to throw the .C files into the cabal file, you'll
run into an issue with cabal calling gcc instead of g++ on the C++ sources.
gcc might do the right thing for you, but my experience is that the result
is thorny.

The approach I've managed to get working is to have cabal call g++ in place
of gcc, which works for both C and C++ sources.

Thanks,
Arjun

On Mon, Jan 26, 2015 at 5:37 PM, Donn Cave <donn at avvanta.com> wrote:

> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150126/28c42c01/attachment.html>


More information about the Haskell-Cafe mailing list