Xcode14 crash on launch: dyld: Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib
Asked Answered
P

6

7

When I upgrade my Xcode to 14, my app crashed and Get an error message: dyld: Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib

It's only happen on devices with iOS version below 13,like iOS 12/11,

Plio answered 20/9, 2022 at 7:41 Comment(0)
R
1

most likely an interoperability issue between Xcode 14 and older iOS version devices. It has been reported multiple times in GitHub issues. Check this post in Apple Developer Forum.

So for solutions: add libSwiftCoreGraphics.tbd to your project's Frameworks,Libraries,and Embeded Contents.

If you are using pods or SPM, also check the updates from the author. For example, SnapKit just upadted their podfile 5 days ago

enter image description here

Reconcile answered 20/9, 2022 at 11:15 Comment(1)
This solution does not work for me. There's another ongoing thread on Apple Developer Forums, saying "this is an issue on the Apple side of things."Depredation
H
4

As per https://developer.apple.com/forums/thread/714795, Apple suggested adding -Wl,-weak-lswiftCoreGraphics to the linker flags.

The problem was that without this flag your app will expect libswiftCoreGraphics.dylib to be at /usr/lib/swift/libswiftCoreGraphics.dylib on the phone. Because the dylib isn't there on older iOS versions, you'll get error like

EXC_CRASH (SIGABRT)
Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Description: DYLD, Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib 

Adding the flag tells the linker to treat this library as a weak linker flag. At the launch(or load) time, the dylib will be searched relative to the @rpath instead of hard coded /usr/lib/swift path.

You can learn more about rpath and how that helps dyld find the dylibs here

After running otool -L on the app I see few more libraries pointing to their /usr/lib/swift version but all of them are weak references e.g,

    /usr/lib/swift/libswiftCoreMIDI.dylib (compatibility version 1.0.0, current version 6.0.0, weak)
    /usr/lib/swift/libswiftCoreML.dylib (compatibility version 1.0.0, current version 1436.0.14, weak)
    /usr/lib/swift/libswiftDataDetection.dylib (compatibility version 1.0.0, current version 723.0.0, weak)
    /usr/lib/swift/libswiftFileProvider.dylib (compatibility version 1.0.0, current version 730.0.125, weak)
    /usr/lib/swift/libswiftOSLog.dylib (compatibility version 1.0.0, current version 4.0.0, weak)
...

The only library with non-weak reference was libswiftCoreGraphics before adding the linker flag.

/usr/lib/swift/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 120.100.0)

After adding the linker flag it appears as:

@rpath/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 15.0.0, weak)
Hollywood answered 24/9, 2022 at 4:41 Comment(3)
It works for me and your explanation makes me clear. Thanks very much.Neilla
@A.K I am not sure, wouldnt it be more wise to add /usr/lib/swift/ with @executable_path to the LD_RUNPATH_SEARCH_PATH to make it search in all possible places? instead of weak linking. What will happen if he try to embed and SDK that depend on this libs the weak link wont help here, no?Farnese
I think /usr/lib/swift/ is already added and that is why the setup was working for iOS>12. But on iOS-12.1 the library isn't there. Making libswiftCoreGraphics relative to @rpath the loader is searching for all places as you mentioned.Hollywood
R
1

most likely an interoperability issue between Xcode 14 and older iOS version devices. It has been reported multiple times in GitHub issues. Check this post in Apple Developer Forum.

So for solutions: add libSwiftCoreGraphics.tbd to your project's Frameworks,Libraries,and Embeded Contents.

If you are using pods or SPM, also check the updates from the author. For example, SnapKit just upadted their podfile 5 days ago

enter image description here

Reconcile answered 20/9, 2022 at 11:15 Comment(1)
This solution does not work for me. There's another ongoing thread on Apple Developer Forums, saying "this is an issue on the Apple side of things."Depredation
S
1

The framework you are trying to compile might be dynamic framework. Try changing your "Embed" content of your framework from "Do not Embed" to "Embed & Sign" this might fix your crash enter image description here

Sniffy answered 29/8, 2023 at 5:58 Comment(0)
S
0

With Xcode14.1 RC 2 this issue has been fixed.

Sulphide answered 26/10, 2022 at 6:57 Comment(0)
U
0

I got it after updating some pod to Dynamic lyb. Just clean Derived Data, Clean project and run again

Undertint answered 27/10, 2023 at 8:58 Comment(0)
F
0

Here are some steps to Solve the issue. Based on error below methods may helps you to solve the issue. Xcode Version 15.4 (15F31d)

First Update All POD to Latest

By deleting Xcode's Derived Data directory.

OR

In the Framework Target (not the app target), go to Build Settings > Build Options > Always Embed Standard Swift Libraries to YES.

OR

Min Deployment to 13.0

AND

Clean the build folder: Product -> Clean Build Folder

Frerichs answered 13/7, 2024 at 9:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.