xcode dyld:库未加载:@rpath/libswiftSwiftOnoneSupport.dylib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40986082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:37:54  来源:igfitidea点击:

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

iosswiftxcode

提问by Tim Dean

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:

我已经构建了一个 Swift 框架,现在我正在尝试构建一个将使用该框架的 Swift iOS 应用程序。我收到此错误:

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:

我搜索了 SO 并找到了类似的报告并尝试了那里列出的修复程序,包括:

  • Clearing out my DerivedData folder
  • Restarting Xcode and the iPhone simulator
  • Ensuring that Always Embed Swift Standard Libraries = YESis set, both in my framework and my application's build settings
  • Ensuring that Enable Bitcode=NOis set, both in my framework and my application's build settings
  • Ensuring that Runpath Search Pathsis 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.
  • 清除我的 DerivedData 文件夹
  • 重启 Xcode 和 iPhone 模拟器
  • 确保Always Embed Swift Standard Libraries = YES在我的框架和我的应用程序的构建设置中设置
  • 确保Enable Bitcode=NO在我的框架和我的应用程序的构建设置中设置
  • 确保Runpath Search Paths被设置为@executable_path/Frameworks,无论是在我的框架和我的应用程序的构建设置
  • 将我的 Xcode 安装中的所有 libswift 文件复制到我项目中的本地副本中,并添加了一个自定义构建阶段以将这些文件复制到框架文件夹中。

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)
  • Xcode 8.1 版 (8B62)
  • Apple Swift 3.0.1 版 (swiftlang-800.0.58.6 clang-800.0.42.1)

回答by Tim Dean

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 Librariesto a value of YESin the build settings tab for both my Swift framework and in the Swift application that uses the framework.
  2. I have added Foundation.frameworkto 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.frameworkto the Embedded Binaries section of the general tab for the Swift application that uses the framework.
  1. 我在构建设置选项卡中为我的 Swift 框架和使用该框架的 Swift 应用程序设置Always Embed Swift Standard Libraries了一个值YES
  2. 我已将Foundation.frameworkSwift 框架和使用该框架的 Swift 应用程序添加到常规选项卡的链接框架和库部分。
  3. 我已将Foundation.framework使用该框架的 Swift 应用程序添加到常规选项卡的嵌入式二进制文件部分。

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

有了所有这 3 个设置,我就可以构建和运行我的应用程序而不会遇到此错误。

回答by S2dent

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.

我有一个由框架和测试目标组成的空项目,在运行测试时出现此错误。显然 Swift 非常聪明地检测到您实际上并不需要这个库并且没有链接到libswiftSwiftOnoneSupport.dylib.

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

修复只是添加一些代码,我刚刚添加:

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

and libswiftSwiftOnoneSupport.dylibgot linked.

libswiftSwiftOnoneSupport.dylib得到了联系。

回答by LuisCien

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 specificallyusing print()anywhere in the code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded and the issue will go away.

事实证明,在代码中的任何地方专门使用print()会以某种方式强制加载 libswiftSwiftOnoneSupport.dylib,问题就会消失。

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

我使用的是 Xcode 10.1、Swift 4.2,给我带来这个问题的 pod 是 Nimble。

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

顺便说一句,我知道@S2dent的建议是“只添加一些代码”,但在我的情况下,我的框架已经有几个不同的类,所以它对我没有帮助。

回答by weissazool

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

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.

原来这与 Swift 全模块优化有关。

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.

使用 Carthage 作为依赖管理器,它们被编译为 Release,因此编译时使用了全模块优化,Xcode 建议我打开它。在模拟器上运行应用程序会编译它以进行调试。我猜动态框架不能与运行它的应用程序处于不同的优化级别。

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.

解决方案是明确指定我希望 Carthage 构建的配置。( carthage bootstrap --configuration Debug) 哦,当然还有清理我的构建文件夹。

回答by Peterdk

I had the same issue, adding the library (my own build one) to Linked Frameworks and Librariesin Generaltab of the app solved the issue.

我有同样的问题,增加了库(我自己建立一个),以Linked Frameworks and LibrariesGeneral应用程序的标签解决的问题。

回答by Arnaud Dorgans

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

如果您不想将 Foundation.framework 添加到链接框架或嵌入式二进制文件,您还可以向测试目标提供主机应用程序

回答by Joris Weimar

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

您可以通过在目标的构建设置中将“始终嵌入 Swift 标准库”设置为“是”来解决此问题。

回答by yoAlex5

It is an dynamic linkererror which links binary in load or runtime

这是一个动态链接器错误,它在加载或运行时链接二进制文件

[@rpath]

[@rpath]