[Haskell-cafe] Wrapping a C++ library
rasen.dubi at gmail.com
Mon Jan 26 22:49:39 UTC 2015
I'm not an expert in writing Haskell binding but pretty much experienced in
You shouldn't force compilation of .c files with g++. Instead, you should
keep your wrapping functions as extern "C" and place their implementation
in .cpp file (which of course should be compiled with g++). Don't forget to
link to C++ runtime library (-lstdc++).
There is also a wiki page that describes how to call C++ from Haskell.
2015-01-26 23:27 GMT+02:00 Arjun Comar <nrujac at gmail.com>:
> 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).
> On Mon, Jan 26, 2015 at 11:29 AM, Donn Cave <donn at avvanta.com> wrote:
>> Quoth Richard Lewis <richard.lewis at gold.ac.uk>,
>> > There's a specific question here which goes something like: how do I
>> > get hsc2hs to compile code that uses STL headers?
>> For me, that would be the first thing to fix. Use #ifdef __cplusplus,
>> or just reorganize, so the hsc2hs-generated files are just C.
>> You wrote your wrapper library for the C++ part, and if the callers
>> need to be C++ it kind of defeats the purpose.
>> From there, I would have guessed "extra-libraries: stdc++" would do it,
>> (assuming you have also arranged to get your wrapper library in there),
>> but I'm no cabal expert. I use C++ more or less like you're doing, so
>> there's hope, but I haven't gotten around to the cabal part of the
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe