Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Linking with dynamic libraries on OS X fails due to absolute path in libffi.dylib #27

Open
AndreasVoellmy opened this issue Oct 2, 2013 · 2 comments

Comments

@AndreasVoellmy
Copy link

I ran into a problem compiling an executable using shared libraries. I am using OS X 10.8.5 with HP 2013.2.0.0 64 bit.

First I cabal installed a tiny one-module package with --enable-shared. Then I have a tiny executable that uses the module in this package, which I compiled with "ghc --make Main.hs -dynamic". Then when I run it I get:

dyld: Library not loaded: /Users/ian/zz64/ghc-7.6.3/libffi/build/inst/lib/libffi.6.dylib
Referenced from: /usr/local/lib/ghc-7.6.3/libHSrts-ghc7.6.3.dylib
Reason: image not found
Trace/BPT trap: 5

Turns out the dynamic library for the HSrts package in the HP refers to libffi with a hard-coded path to Ian's machine!

$ otool -L /usr/local/lib/ghc-7.6.3/libHSrts-ghc7.6.3.dylib
/usr/local/lib/ghc-7.6.3/libHSrts-ghc7.6.3.dylib:
/usr/local/lib/ghc-7.6.3/libHSrts-ghc7.6.3.dylib (compatibility version 0.0.0, current version 0.0.0)
/Users/ian/zz64/ghc-7.6.3/libffi/build/inst/lib/libffi.6.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

There is a file /usr/local/lib/ghc-7.6.3/libffi.dylib , but it too depends on Ian's path:

$ otool -L /usr/local/lib/ghc-7.6.3/libffi.dylib
/usr/local/lib/ghc-7.6.3/libffi.dylib:
/Users/ian/zz64/ghc-7.6.3/libffi/build/inst/lib/libffi.6.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

@AndreasVoellmy
Copy link
Author

Note that this same problem occurs if I build the executable using cabal with option --enable-executable-dynamic.

@AndreasVoellmy
Copy link
Author

Running the following commands fixed the problem:

cd /usr/local/lib/ghc-7.6.3
sudo install_name_tool -change /Users/ian/zz64/ghc-7.6.3/libffi/build/inst/lib/libffi.6.dylib @loader_path/libffi.dylib libHSrts-ghc7.6.3.dylib
sudo install_name_tool -change /Users/ian/zz64/ghc-7.6.3/libffi/build/inst/lib/libffi.6.dylib @loader_path/libffi.dylib libHSrts_thr-ghc7.6.3.dylib
sudo install_name_tool -id @rpath/libffi.dylib libffi.dylib

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants