[Haskell-cafe] Building foreign shared libraries with Cabal

Albert Y. C. Lai trebla at vex.net
Sat Apr 26 18:00:04 UTC 2014

On 14-04-21 04:25 AM, Nikolay Amiantov wrote:
> I want to use cabal to build and install shared library, which will be
> called from C. I've already found necessary combination of flags and
> options to successfully build it, but now I have two main issues:
> 1) The library is installed into "bin".
> 2) The generated "stub" C headers are not installed at all.
> How can I resolve this? My current options is as follows:
> executable libtest.so

See my http://www.vex.net/~trebla/haskell/so.xhtml for how to use 
"library" instead. It has the advantage of needing no ghc-options or 
cc-options, and installing into "lib/xxx-1.0/ghc-n.n.n". It has the 
disadvantage of losing control over the filename---it must be 

Combine "include-dirs" and "install-includes" for the C header. It will 
be installed into "lib/xxx-1.0/ghc-n.n.n/include". However, you have a 

* If you use the generated file under dist/build, cabal warns you that 
dist/build is not to be relied upon, and it is right. Also, it depends 
too much on HsFFI.h.

* If you hand-write the file yourself, you worry that it mismatches the 
Haskell export, and you are right.

More information about the Haskell-Cafe mailing list