-
You’ll need to use
extra-lib-dirsandextra-librariesin theexecutablesection of your.cabalfile like so:name: MyApp version: 0.1.0.0 synopsis: homepage: author: simon.bourne category: build-type: Simple cabal-version: >=1.10 library exposed-modules: HelloWorld build-depends: base >= 4.7 && < 5 hs-source-dirs: src default-language: Haskell2010 executable MyApp main-is: Main.hs extra-lib-dirs: lib extra-libraries: helloWorld build-depends: base >= 4.7 && < 5, MyApp hs-source-dirs: app default-language: Haskell2010Put your dll and .so in
lib. Be warned, you’ll run into link order problems if you use a static library (.ainstead of.so) on linux.See this for an example. Don’t be fooled by the name as it works fine with
.sofiles. -
stack ghcishould just work provided it can find your library (LD_LIBRARY_PATHon linux). -
The C API (mentioned in the comments on your question) is already there. You just need to write the Haskell FFI signatures, for example:
foreign import ccall safe "helloWorld" c_helloWorld :: IO ()I’d very strongly advise using
safeccalls, and don’t wrap the functions inunsafePerformIO.If you need to pass non opaque structs, you might want to investigate
c2hsorhsc2hs, but I don’t think you’ll need to. See this question for more details.