[Haskell-cafe] Calling Haskell from C

dominic at steinitz.org dominic at steinitz.org
Sat Jan 14 08:46:59 UTC 2017


That does look useful. I think I won’t complicate my environment even more with an experimental version of cabal but I look forward to its release.

> On 13 Jan 2017, at 18:29, Auke Booij <auke at tulcod.com> wrote:
> 
> The development version of cabal has support for building dynamic objects. See:
> https://github.com/haskell/cabal/blob/master/Cabal/doc/developing-packages.rst#foreign-libraries
> 
> On 13 January 2017 at 10:59, Dominic Steinitz <dominic at steinitz.org> wrote:
>> I've been trying to get the example in
>> https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.html?highlight=foreign#using-foreign-export-and-foreign-import-ccall-wrapper-with-ghc
>> working.
>> 
>> I have a cabal file
>> 
>> name:                test-via-c
>> version:             0.1.0.0
>> 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
>> 
>> /Users/dom/Library/Haskell/ghc-8.0.1/lib/test-via-c-0.1.0.0/bin/Foo.dylib
>> 
>> I then compile the C with
>> 
>> gcc-6 Bar.c
>> /Users/dom/Library/Haskell/ghc-8.0.1/lib/test-via-c-0.1.0.0/bin/Foo.dylib
>> -I/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/include
>> -L/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/rts
>> -lHSrts-ghc8.0.1
>> 
>> 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
>> error.
>> 
>> 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
>> http://idontgetoutmuch.wordpress.com
>> 
>> 
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.

Dominic Steinitz
dominic at steinitz.org
http://idontgetoutmuch.wordpress.com



More information about the Haskell-Cafe mailing list