It turns out that what I describe above doesn't work (and I can't seem to edit or delete my answer?), at least not on recent macOS with SIP enabled. Regardless of how you try to do it (setenv/putenv followed by exec, or via LSEnvironment), all environment variables starting with DYLD_ are ignored (scrubbed out of the environment, in fact). I haven't tested it, because then I also found that it was working for me even without setting DYLD_LIBRARY_PATH (perhaps I was missing a library that needed to be patched to use @executable_path? unclear), but I believe the entitlement mentioned by Quinn (@eskimo) above will fix that.
Post
Replies
Boosts
Views
Activity
It turns out that what I describe above doesn't work (and I can't seem to edit or delete my answer?), at least not on recent macOS with SIP enabled. Regardless of how you try to do it (setenv/putenv followed by exec, or via LSEnvironment), all environment variables starting with DYLD_ are ignored (scrubbed out of the environment, in fact).
I haven't tested it, because then I also found that it was working for me even without setting DYLD_LIBRARY_PATH (perhaps I was missing a library that needed to be patched to use @executable_path? unclear), but I believe this entitlement will allow the use of the DYLD_* environment variables:
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_allow-dyld-environment-variables?language=objc