Example: Binding C++ to Haskell using the ffi
Sven Panne
Sven.Panne at aedion.de
Sat Dec 13 06:51:26 EST 2003
David Sankel wrote:
> [...] Would stubs on the c++ side be generated or would it use the code directly.
Well, I've pointed this out several times already, but I'd like to repeat it here:
Apart from the ABI issues already mentioned (name mangling, calling convention, etc.)
there is still the problem of a completely different runtime system. So if anything
in your code is C++, you have to link everything together with the C++ compiler used
to compile the C++ part. Full stop. If you are lucky (e.g. you are using GCC and/or
don't use things which need sepcial runtime and/or linker support like exceptions,
global variables of a class type, templates, etc.), you might only need to add C++
RTS libraries to the final link stage. But I know some platforms where this is simply
not enough. So the most portable way will probably be generating C wrappers, compile
them with the C++ compiler, use C marshaling on the Haskell side, and use the same
C++ compiler in the linking stage.
Cheers,
S.
More information about the FFI
mailing list