
I've been trying to get the example in https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.htm... working. I have a cabal file name: test-via-c version: 0.1.0.0 homepage: TBD license: MIT author: Dominic Steinitz maintainer: idontgetoutmuch@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@steinitz.org http://idontgetoutmuch.wordpress.com

Answering my own question:
export DYLD_LIBRARY_PATH=/Users/dom/Library/Haskell/ghc-8.0.1/lib/test-via-c-0.1.0.0/bin:/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/rts
./a.out 2500 2500 2500 2500 2500
On 13 Jan 2017, at 10:59, Dominic Steinitz
wrote: I've been trying to get the example in https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.htm... https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.htm... working.
I have a cabal file
name: test-via-c version: 0.1.0.0 homepage: TBD license: MIT author: Dominic Steinitz maintainer: idontgetoutmuch@gmail.com mailto:idontgetoutmuch@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@steinitz.org mailto:dominic@steinitz.org http://idontgetoutmuch.wordpress.com http://idontgetoutmuch.wordpress.com/
Dominic Steinitz dominic@steinitz.org http://idontgetoutmuch.wordpress.com

On Fri, Jan 13, 2017 at 8:53 AM,
export DYLD_LIBRARY_PATH=/Users/dom/Library/Haskell/ghc-8.0.1/lib/ test-via-c-0.1.0.0/bin:/Library/Frameworks/GHC. framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/rts
That's a good way to break things. Consider DYLD_FALLBACK_LIBRARY_PATH instead. Also, use otool -l a.out to inspect the RPATH commands embedded in a.out; that will tell you where dyld searches when it sees @rpath/Foo.dylib. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Thanks very much - I am very ignorant in this area and all help is much appreciated. However, when I do as you suggest I get
$ otool -L a.out a.out: @rpath/Foo.dylib (compatibility version 0.0.0, current version 0.0.0) @rpath/libHSrts-ghc8.0.1.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1) /usr/local/lib/gcc/6/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) $ set | grep -i dyld DYLD_FALLBACK_LIBRARY_PATH=/Users/dom/Library/Haskell/ghc-8.0.1/lib/test-via-c-0.1.0.0/bin:/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/rts ~/Dropbox/Private/TestU01-1.2.3/examples/src $ ./a.out dyld: Library not loaded: /usr/local/lib/gcc/5/libgcc_s.1.dylib Referenced from: /Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/rts/libHSrts-ghc8.0.1.dylib Reason: image not found Trace/BPT trap: 5
It’s not clear to me why it’s looking for `gcc/5` which is not installed when it looks as though it should be looking for `gcc/6`.
On 13 Jan 2017, at 16:06, Brandon Allbery
wrote: On Fri, Jan 13, 2017 at 8:53 AM,
mailto:dominic@steinitz.org> wrote: export DYLD_LIBRARY_PATH=/Users/dom/Library/Haskell/ghc-8.0.1/lib/test-via-c-0.1.0.0/bin:/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/rts
That's a good way to break things. Consider DYLD_FALLBACK_LIBRARY_PATH instead. Also, use otool -l a.out to inspect the RPATH commands embedded in a.out; that will tell you where dyld searches when it sees @rpath/Foo.dylib.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com mailto:allbery.b@gmail.com ballbery@sinenomine.net mailto:ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net http://sinenomine.net/ Dominic Steinitz dominic@steinitz.org http://idontgetoutmuch.wordpress.com

On Fri, Jan 13, 2017 at 12:35 PM,
$ otool -L a.out
I said "-l". "-L" shows how it resolves shared objects; "-l" dumps the
load commands table, which includes RPATH entries that tell it how to resolve @rpath.
DYLD_FALLBACK_LIBRARY_PATH=/Users/dom/Library/Haskell/ghc- 8.0.1/lib/test-via-c-0.1.0.0/bin:/Library/Frameworks/GHC. framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/rts ~/Dropbox/Private/TestU01-1.2.3/examples/src $ ./a.out
This is odd, unless Apple changed things yet again (I should not be surprised, the loader stuff is about as stable as water /o\ )
It’s not clear to me why it’s looking for `gcc/5` which is not installed
when it looks as though it should be looking for `gcc/6`.
That might be indicated by the RPATH entries, since DYLD_FALLBACK_LIBRARY_PATH changes how lookups work (so does DYLD_LIBRARY_PATH, in a different way, which is why it's dangerous). -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Apologies. I put the output of “-l” (not “-L”) here: https://gist.github.com/idontgetoutmuch/654007ac57e863a293b76a0cf98250c1 https://gist.github.com/idontgetoutmuch/654007ac57e863a293b76a0cf98250c1 I couldn’t immediately see anything that tells me how @rpath is resolved.
On 13 Jan 2017, at 17:46, Brandon Allbery
wrote: On Fri, Jan 13, 2017 at 12:35 PM,
mailto:dominic@steinitz.org> wrote: $ otool -L a.out
I said "-l". "-L" shows how it resolves shared objects; "-l" dumps the load commands table, which includes RPATH entries that tell it how to resolve @rpath.
DYLD_FALLBACK_LIBRARY_PATH=/Users/dom/Library/Haskell/ghc-8.0.1/lib/test-via-c-0.1.0.0/bin:/Library/Frameworks/GHC.framework/Versions/8.0.1-x86_64/usr/lib/ghc-8.0.1/rts ~/Dropbox/Private/TestU01-1.2.3/examples/src $ ./a.out
This is odd, unless Apple changed things yet again (I should not be surprised, the loader stuff is about as stable as water /o\ )
It’s not clear to me why it’s looking for `gcc/5` which is not installed when it looks as though it should be looking for `gcc/6`.
That might be indicated by the RPATH entries, since DYLD_FALLBACK_LIBRARY_PATH changes how lookups work (so does DYLD_LIBRARY_PATH, in a different way, which is why it's dangerous).
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com mailto:allbery.b@gmail.com ballbery@sinenomine.net mailto:ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net http://sinenomine.net/ Dominic Steinitz dominic@steinitz.org http://idontgetoutmuch.wordpress.com

On Sat, Jan 14, 2017 at 8:45 AM,
Apologies. I put the output of “-l” (not “-L”) here: https://gist.github.com/idontgetoutmuch/654007ac57e863a293b76a0cf98250c1
I couldn’t immediately see anything that tells me how @rpath is resolved.
Hm, no RPATH entries indeed. There's no fallback for executables, so it's probably not even looking for the library but just failing immediately. You could probably make this work by forcing an RPATH entry (-Wl,-rpath,...). (Or, use "install_name_tool -add_rpath the_path_here a.out" to patch one into the existing binary.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

The development version of cabal has support for building dynamic objects. See:
https://github.com/haskell/cabal/blob/master/Cabal/doc/developing-packages.r...
On 13 January 2017 at 10:59, Dominic Steinitz
I've been trying to get the example in https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.htm... working.
I have a cabal file
name: test-via-c version: 0.1.0.0 homepage: TBD license: MIT author: Dominic Steinitz maintainer: idontgetoutmuch@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@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.

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
wrote: The development version of cabal has support for building dynamic objects. See: https://github.com/haskell/cabal/blob/master/Cabal/doc/developing-packages.r...
On 13 January 2017 at 10:59, Dominic Steinitz
wrote: I've been trying to get the example in https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.htm... working.
I have a cabal file
name: test-via-c version: 0.1.0.0 homepage: TBD license: MIT author: Dominic Steinitz maintainer: idontgetoutmuch@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@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@steinitz.org http://idontgetoutmuch.wordpress.com
participants (4)
-
Auke Booij
-
Brandon Allbery
-
Dominic Steinitz
-
dominic@steinitz.org