Library not loaded: @rpath/libswiftCompatibilitySpan.dylib – Building bundle target

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)

Thanks for the post.

Based on your description, you are encountering an issue with loading the library and deploying it into macOS versions 15?

I believe there was a bug on previous versions of Xcode, but that should have been fixed. Are you using Xcode 26.2 to build the app?

The error message indicates that the library cannot be found at runtime, despite being included in your build setup.

If you are getting this error on macOS Sonoma with the app build in Xcode 26.2, it means the bug is on that version of macOS. If you are not getting the error in macOS Tahoe, the bug has been fixed. The good news is that the bug has been fixed, but the bad news is that the bug is also in macOS 15? And it was not just Xcode as I initially thought.

Can you confirm that when you deploy the app built in Xcode 26.2 to macOS 15, you still encounter this bug?

Albert Pascual
  Worldwide Developer Relations.

Based on your description, you are encountering an issue with loading the library and deploying it into macOS versions 15?

Correct.

Can you confirm that when you deploy the app built in Xcode 26.2 to macOS 15, you still encounter this bug?

That is the case. I sm compiling with Xcode 26.2 using macOS 26.2 (25C57) SDK (Built-in) targeting macOS 12 and later.

The error occurs on macOS 15.7.3 but not on macOS 26. I suspect this is because macOS provides the Span API natively and thus does not need to access the backdeployment dylib, unlike macOS 15 where this API is not available natively.

Talking to people working on Swift, they interpreted this to be an Xcode issue, stating:

Xcode should (somehow) bundle libswiftCompatibilitySpan with it, but it doesn’t, leading to the failure on macOS 15.x.

Library not loaded: &#64;rpath/libswiftCompatibilitySpan.dylib – Building bundle target
 
 
Q