System frameworks cannot be loaded on macOS Big Sur
Summary
When running on macOS Big Sur, attempting to load a system framework at runtime fails with a not found
error.
Steps to reproduce
Create a file called Main.hs
with the following content:
module Main where
main = putStrLn "Hi."
Run it with runghc
, passing -framework OpenGL
to GHC:
runghc --ghc-arg="-framework OpenGL" Main.hs
Expected behavior
The program should run and say hi.
Environment
- GHC version used: 8.10.1
- Operating System: macOS 10.16 Big Sur (20A4300b)
- System Architecture: x86_64
Proposed Fix
Merge request !3689 (closed) is a proposed fix.
Remarks
This is presumably due to the following change in macOS Big Sur:
New in macOS Big Sur 11 beta, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache. (62986286)
(https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes/)
The fix proposed above implements the behavior suggested there.