[Haskell-cafe] Calling Haskell from C

Dominic Steinitz dominic at steinitz.org
Fri Jan 13 10:59:40 UTC 2017

I've been trying to get the example in

I have a cabal file

name:                test-via-c
homepage:            TBD
license:             MIT
author:              Dominic Steinitz
maintainer:          idontgetoutmuch at gmail.com
category:            System
build-type:          Simple
cabal-version:       >=1.10

executable Foo.dylib
  main-is: Foo.hs
  other-extensions:    ForeignFunctionInterface
  build-depends:       base >=4.7 && <4.10,
                       primitive >=0.6 && <0.7
  hs-source-dirs:      src
  default-language:    Haskell2010
  include-dirs:        src
  ghc-options:         -O2 -shared -fPIC -dynamic
  extra-libraries:     HSrts-ghc8.0.1

which installs


I then compile the C with

gcc-6 Bar.c

Sadly when I try to run the executable I get

~/Dropbox/Private/TestU01-1.2.3/examples/src $ ./a.out
dyld: Library not loaded: @rpath/Foo.dylib
  Referenced from: /Users/dom/Dropbox/Private/TestU01-1.2.3/examples/src/./a.out
  Reason: image not found
Trace/BPT trap: 5

I am guessing the executable is looking for the dynamic library. I
copied Foo.dylib to the current directory but still get the same

I know this is really an OS X question but I am hoping someone who has
done before will be able to help.

Dominic Steinitz
dominic at steinitz.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170113/aad256e5/attachment.html>

More information about the Haskell-Cafe mailing list