
#8266: Dynamic linking on Mac --------------------------------------------+------------------------------ Reporter: kazu-yamamoto | Owner: Type: bug | thoughtpolice Priority: highest | Status: closed Component: Build System | Milestone: 7.8.1 Resolution: fixed | Version: 7.7 Operating System: MacOS X | Keywords: Type of failure: GHC doesn't work at all | Architecture: Test Case: | Unknown/Multiple Blocking: | Difficulty: Unknown | Blocked By: | Related Tickets: --------------------------------------------+------------------------------ Comment (by darchon): I currently don't have my OS X machine, so I can't make the patch right now. But the patch should be "straightforward": just make OS X (MACH-O) behave the same way as Linux (ELF). I guess this whole mess started in the first place because MACH-O only has absolute paths to dynamic libraries. Currently on OS X there's a single point of reference, an `@rpath`, that's pointing to a `lib/` directory, and expecting all libraries bundled with GHC to be there. This should be changed to multiple `@rpath`s. So the current situation looks like this: {{{ -- Installed by GHC install @rpath/package1-package1version/package1.dylib @rpath/package2-package1version/package2.dylib @rpath/package3-package1version/package3.dylib -- Installed by Cabal /absolute_path_to_library/package4.dylib /absolute_path_to_library/package5.dylib }}} Where a executable gets an `@rpath` pointing to the same location as the value of `ghc --print-libdir`. With the exception of the GHC binary, which has an `@rpath` pointing to `@loader_path/..`. The new situation should be: {{{ -- Installed by GHC install @rpath/package1.dylib @rpath/package2.dylib @rpath/package3.dylib -- Installed by Cabal @rpath/package4.dylib @rpath/package5.dylib }}} Where: * Libraries bundled with GHC should get, for all transitively depending libraries, an `@rpath` pointing to `@loader_path/../dependentpackage/` (similar to the situation on Linux, which uses `$ORIGIN/../dependentpackage/`) * The GHC executable should get, for all transitively depending libraries, an `@rpath` pointing to `@loader_path/../dependentpackage/` (again similar to Linux) * Libraries installed by Cabal should get, for all transitively depending library, an `@rpath` pointing to `/absolute_path_to_package` (similar to linux) * Executables should get, for all transitively depending libraries, an `@rpath` pointing to `/absolute_path_to_package` (similar to linux) This patch would involve adding a code-path for OS-X/MACH-O similar to lines 1757-1776 in `compiler/main/DriverPipeline.hs`, and of course changing `rules/relative-dynlib-references.mk`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8266#comment:30 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler