[Haskell-cafe] Exporting Haskell Libraries to C Programmers

Don Stewart dons at galois.com
Wed Feb 20 16:45:39 EST 2008


joseph.bruce:
> Hi,
> 
> I have a Haskell library that I want to make available via FFI to C
> programmers on my project team.  I read this thread
> (http://thread.gmane.org/gmane.comp.lang.haskell.cafe/21447) which had
> some interesting ideas, but they seemed unresolved.  Or maybe it answers
> my question but I don't understand it.
> 
> Is there a way I can package (ghc-)compiled Haskell code into a
> statically-linked library and not force the C programmers to include
> headers and libraries that they have no knowledge of and undefine a
> seemingly endless list of preprocessor symbols (run ghc with the verbose
> flag and look at the calls to gcc)?  Can this process be automated?

Yes, check the FFI documentation for the main story. 

In short, build the Haskell code with cabal, with your foreign export
Haskell functions in the cbits. That bundle can then be linked against
C code.

You do need to link your app against libHSrts.a and libHSbase.a (and
other libs you use), but assuming you foreign export, the code 
to call will look just like normal C stuff.

-- Don


More information about the Haskell-Cafe mailing list