Building foreign shared libraries with Cabal

Hello, 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 hs-source-dirs: src main-is: Test.hs default-language: Haskell2010 default-extensions: ForeignFunctionInterface build-depends: base >= 4.7 c-sources: cbits/library_init.c ghc-options: -no-hs-main -shared -dynamic cc-options: -DMODULE=Test -fPIC Thanks for any help and have a nice day, Nikolay.

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 "libHSxxx-1.0-ghcn.n.n.so". 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 dilemma: * 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.
participants (2)
-
Albert Y. C. Lai
-
Nikolay Amiantov