dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib
Asked Answered
Z

8

26

I've built a Swift framework and now I'm trying to start building a Swift iOS application that will use that framework. I'm getting this error:

dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib
  Referenced from: /Users/tdean/Library/Developer/Xcode/DerivedData/NFLApplication-ejmafvjrlqgjaabggwvadjarjjlg/Build/Products/Debug-iphonesimulator/NFLStatsModel.framework/NFLStatsModel
  Reason: image not found

I've scoured SO and found similar reports and tried the fixes listed there, including:

  • Clearing out my DerivedData folder
  • Restarting Xcode and the iPhone simulator
  • Ensuring that Always Embed Swift Standard Libraries = YES is set, both in my framework and my application's build settings
  • Ensuring that Enable Bitcode=NO is set, both in my framework and my application's build settings
  • Ensuring that Runpath Search Paths is set to @executable_path/Frameworks, both in my framework and my application's build settings
  • Copied all the libswift files from my Xcode installation into a local copy within my project, and added a custom build phase to copy those files into the frameworks folder.

In every case, I get the same error when I try to run my application.

  • Xcode Version 8.1 (8B62)
  • Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)
Zhang answered 6/12, 2016 at 0:59 Comment(4)
longshot suggestion: add @executable_path/../Frameworks to your runtime search paths on your framework.Inevitable
@JoeDaniels - No difference when I add that. Thanks for the suggestion.Zhang
Oh, what about Swift language version? is it all 3.0?Inevitable
Updated issue to include Swift versionZhang
Z
46

I eventually got this working using a mix of fixes. I'm not sure if all of them are needed, but I'm documenting what seemed to work for me here, just in case anyone else can benefit by what I've found.

  1. I have set Always Embed Swift Standard Libraries to a value of YES in the build settings tab for both my Swift framework and in the Swift application that uses the framework.
  2. I have added Foundation.framework to the Linked Frameworks and Libraries section of the general tab for both my Swift framework and in the Swift application that uses the framework.
  3. I have added Foundation.framework to the Embedded Binaries section of the general tab for the Swift application that uses the framework.

With all 3 of these settings in place, I am able to build and run my application without encountering this error.

Zhang answered 9/12, 2016 at 2:28 Comment(7)
THANK YOU! I spent two hours setting up a demo app/framework feature of a production app I'm working on. Twice while building things I encountered this exact error. For some reason I could loop (iterate) through an array of custom UIButtons in the framework, but the moment I tried to actually access something in the loop I got this error. FYI: I tested each thing and the only one I needed to add was #1. This new feature has been developed solely in Xcode 8 and is working (I don't know why) in a branch off of things, but not in any other newly created project - until now.Gist
It was enough for me to fulfill the 1st point of your instruction. Thank you.Parquet
Point 1 alone solved it for me. I find it strange that you have to put it on the app AND on the linked framework. XCode's dependencies management is a source of perplexity. Any other way to make it automatic?Barred
I had this problem on a unit test target. Adding Foundation.framework on the Link Binary with Libraries of the test target was enough for me.Penland
Point 1 solved it for me.Of note, this was happening with an embedded custom frameworkBazan
If you're using CocoaPods, set this flag for Pods project as well 🤦🏻‍♂️Runagate
I also had this issue using Xcode 11 and trying to run the tests against a simulator on iOS 11. It seems a lot of things can cause this issue 😞Boote
B
27

This might not be the case for everyone, but I solved it by actually writing some code in the main target.

I had an empty project consisting of a framework and a test target, and when running tests I was getting this error. Apparently Swift is pretty smart to detect that you don't actually need this library and does not link to libswiftSwiftOnoneSupport.dylib.

The fix is just to add some code, I just added:

class Test {
    func a() { print ("something") }
}

and libswiftSwiftOnoneSupport.dylib got linked.

Boron answered 6/12, 2018 at 15:41 Comment(6)
"Apparently Swift is pretty smart to detect that you don't actually need this library and does not link to libswiftSwiftOnoneSupport.dylib" Too smart for its own good, since you evidently do.Rupee
Just lost 3 hours on that. Warning: I had just struct declaration in main target and I was still getting this error. Adding Test class with function made error disappear (!!!). Crazy.Corso
Did you find a different solution for that? Same happened for me, and its strangeBerserk
No, since I actually needed my framework to have some code inside. You could in theory force link to it, but are you sure you need that? As long as your framework will have some code inside, you should be good to go.Boron
This worked for me as well, in a unit test target on iOS 11 & Xcode 10.2. Worth noting that there was no issue on iOS 12. Bizarre.Isabel
Thanks! Turned out a dev had put in a test with no actual code in the methods yet (new module). Disabled that test target in the scheme and boom no more error.Gonna
P
14

After several days of being stuck with this issue I finally found something that worked for me; hopefully this will help others too.

Turns out that specifically using print() anywhere in the code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded and the issue will go away.

I'm using Xcode 10.1, Swift 4.2 and the pod that was giving me this issue was Nimble.

BTW, I am aware of @S2dent's suggestion to "just add some code" but in my case my framework already had several different classes so it didn't help me.

Pumphrey answered 4/2, 2019 at 6:31 Comment(2)
Works for me to... this was the only thing what worked, but how? Why? Can anyone explain it?Gamal
I can't believe it. This is also the correct answer for me. I just added a random print() to a random Swift file in my tests! This smells like a Xcode bug.Teel
K
9

How are you installing your dependencies?

I had a similar issue:

dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib Referenced from: <internal framework> Reason: image not found

It turned out to be related to Swift whole-module optimization.

Using Carthage as a dependency manager, they were being compiled for Release, and thus compiled with whole-module optimization, which Xcode suggested I turn on. Running the app on the simulator compiles it for Debug. I'm guessing that dynamic frameworks cannot be at a different level of optimization from the app running it.

The solution was to explicitly specify the configuration I wanted Carthage to build for. (carthage bootstrap --configuration Debug) Oh, and cleaning my build folder, of course.

Karalee answered 14/12, 2016 at 3:28 Comment(3)
Thanks for the suggestion, but I was not installing any dependencies nor using Carthage. I have a Swift framework of my own creation in one Xcode project. I have a Swift application of my own creation in another Xcode project. I have both projects inside a single Xcode workspace, and I have the framework being referenced by the application.Zhang
Try checking the Optimization Level in the build settings of both your framework and your app.Karalee
Just cleaning my build folder worked for me. I always use option- Xcode > Product > Clean Build FolderBucko
H
3

I had the same issue, adding the library (my own build one) to Linked Frameworks and Libraries in General tab of the app solved the issue.

Helminthic answered 8/10, 2018 at 13:10 Comment(1)
I was running into the same dylib linker error, but with the LinkKit library. Followed your instructions and rebuilt. Works fine now on XCode 12.2 building for iOS 14.2Mom
H
0

You can also provide an Host Application to your test target if you don't want to add Foundation.framework to Linked Frameworks or Embedded Binaries

Hairraising answered 17/4, 2019 at 9:10 Comment(0)
C
0

You can solve this by setting "Always Embed Swift Standard Libraries" to "Yes" in the Build Settings of your target.

Clupeoid answered 5/5, 2019 at 16:11 Comment(0)
D
0

It is an dynamic linker error which links binary in load or runtime

[@rpath]

Durant answered 6/12, 2019 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.