I am building a bundle target for macOS 12 and later using Xcode. The bundle is not a standalone app, but a plug-in that is loaded by a host app. The code is written in Swift and uses the new Span API which is available in the OS-provided standard library in macOS 26 and backdeploys to macOS 10.14.4+.
Xcode should instruct the linker to include libswiftCompatibilitySpan.dylib in the compiled bundle to provide this backdeployment, but that does not happen.
SwiftPM does this additional linking by adding an rpath.
When trying to load the bundle using the NSBundle.loadAndReturnError() API, I get the following error on macOS 15 (and no error on macOS 26):
Error Domain=NSCocoaErrorDomain Code=3588 "dlopen(.../MyBundle.someBundle/Contents/MacOS/MyBundle, 0x0109): Library not loaded: @rpath/libswiftCompatibilitySpan.dylib
Referenced from: <CE92806C-94B7-367E-895D-EF6DF66C7FC2> .../MyBundle.someBundle/Contents/MacOS/MyBundle
Reason: tried: '/usr/lib/swift/libswiftCompatibilitySpan.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libswiftCompatibilitySpan.dylib' (no such file), '/private/Frameworks/libswiftCompatibilitySpan.dylib' (no such file), '.../MyBundle.someBundle/Contents/MacOS/../Frameworks/libswiftCompatibilitySpan.dylib' (no such file), '/usr/lib/swift/libswiftCompatibilitySpan.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libswiftCompatibilitySpan.dylib' (no such file), '/private/Frameworks/libswiftCompatibilitySpan.dylib' (no such file), '.../MyBundle.someBundle/Contents/MacOS/../Frameworks/libswiftCompatibilitySpan.dylib' (no such file)" UserInfo={NSLocalizedFailureReason=The bundle couldn’t be loaded., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=.../MyBundle.someBundle/Contents/MacOS/MyBundle, NSDebugDescription=dlopen(.../MyBundle.someBundle/Contents/MacOS/MyBundle, 0x0109): Library not loaded: @rpath/libswiftCompatibilitySpan.dylib
Referenced from: <CE92806C-94B7-367E-895D-EF6DF66C7FC2> .../MyBundle.someBundle/Contents/MacOS/MyBundle
Reason: tried: '/usr/lib/swift/libswiftCompatibilitySpan.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libswiftCompatibilitySpan.dylib' (no such file), '/private/Frameworks/libswiftCompatibilitySpan.dylib' (no such file), '.../MyBundle.someBundle/Contents/MacOS/../Frameworks/libswiftCompatibilitySpan.dylib' (no such file), '/usr/lib/swift/libswiftCompatibilitySpan.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libswiftCompatibilitySpan.dylib' (no such file), '/private/Frameworks/libswiftCompatibilitySpan.dylib' (no such file), '.../MyBundle.someBundle/Contents/MacOS/../Frameworks/libswiftCompatibilitySpan.dylib' (no such file), NSBundlePath=.../MyBundle.someBundle, NSLocalizedDescription=The bundle “MyBundle” couldn’t be loaded.}
My setup:
- Xcode 26.2
- macOS 26.2 (25C57) SDK (Built-in)