Tim Dean
Tim Dean

Reputation: 8292

dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib

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:

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

Upvotes: 26

Views: 18194

Answers (8)

yoAlex5
yoAlex5

Reputation: 34255

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

[@rpath]

Upvotes: 0

Joris Weimar
Joris Weimar

Reputation: 4931

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

Upvotes: 0

Arnaud Dorgans
Arnaud Dorgans

Reputation: 382

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

Upvotes: 0

LuisCien
LuisCien

Reputation: 6432

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.

Upvotes: 14

S2dent
S2dent

Reputation: 949

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.

Upvotes: 27

Peterdk
Peterdk

Reputation: 16015

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.

Upvotes: 3

weissazool
weissazool

Reputation: 185

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.

Upvotes: 9

Tim Dean
Tim Dean

Reputation: 8292

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.

Upvotes: 46

Related Questions