创建新方案后,xcode 4 无法启动单元测试(带有链接器错误)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6302362/
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-14 21:14:15  来源:igfitidea点击:

xcode 4 fails to initiate unit tests (with linker error) after I created a new scheme

iosxcodeunit-testing

提问by Haoest

My unit tests worked fine in xcode4 until I had to create a new schema to compile a package to run on my device for testing.

我的单元测试在 xcode4 中运行良好,直到我不得不创建一个新模式来编译一个包以在我的设备上运行以进行测试。

All I did was creating a new Target and a new Scheme, now I try to run the unit tests and get the following error:

我所做的只是创建一个新目标和一个新方案,现在我尝试运行单元测试并收到以下错误:

The test bundle at [...]Tests.octest could not be loaded because a link error occurred. It is likely that dyld cannot locate a framework framework or library that the the test bundle was linked against, possibly because the framework or library had an incorrect install path at link time.

由于发生链接错误,无法加载 [...]Tests.octest 中的测试包。dyld 很可能无法定位测试包所链接的框架框架或库,这可能是因为框架或库在链接时的安装路径不正确。

What did I break?

我打破了什么?

采纳答案by Mr. Berna

I've also run across problems with Xcode 4 after adding a target to an existing project. I eventually figured out that the Xcode DerivedData for the project was damaged. By deleting that data, I caused Xcode to rebuild the data and the project returned to normal. I found the data in my home Library folder (~/Library/Developer/Xcode/DerivedData/).

在向现有项目添加目标后,我也遇到了 Xcode 4 的问题。我最终发现该项目的 Xcode DerivedData 已损坏。通过删除该数据,我导致 Xcode 重建数据,项目恢复正常。我在我的主库文件夹 (~/Library/Developer/Xcode/DerivedData/) 中找到了数据。

回答by iandotkelly

Like @Haoest and @Peter DeWeese above's comments to Answer 1 - I had exactly the same problem when I changed the product name.

就像上面@Haoest 和@Peter DeWeese 对答案 1 的评论一样 - 当我更改产品名称时,我遇到了完全相同的问题。

To fix this for the case where you've renamed the product, you need to go to the Build Settings tab of the test target, and change the Linking section - the Debug and Release bundle loader settings. If you have renamed the product - the directory and name of the application may both be incorrect.

要在您重命名产品的情况下修复此问题,您需要转到测试目标的 Build Settings 选项卡,并更改 Linking 部分 - Debug and Release bundle loader 设置。如果您重命名了产品 - 应用程序的目录和名称可能都不正确。

Thanks to both of them for pointing this out - but I thought this alternative fix for this situation deserved a higher profile than a comment.

感谢他们两人指出这一点 - 但我认为这种情况的替代解决方案应该比评论更受关注。

回答by sdsykes

I tried everything (including the other answers and those noted here http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/), but finally found a different solution:

我尝试了一切(包括其他答案和此处注明的答案http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/),但最终找到了不同的解决方案:

Set Deployment Postprocessing (in the Deployment section of Build Settings) to NO for the Debug target.

将 Debug 目标的 Deployment Postprocessing(在 Build Settings 的 Deployment 部分)设置为 NO。

Before I did this, the executable was being stripped, and the link would fail with

在我这样做之前,可执行文件被剥离,链接将失败

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_SomeClassUnderTest", referenced from:
      objc-class-ref in SomeTest.o

No matter that Strip Linked Product and Strip Debug Symbols During Copy were set to NO, it made no difference - only changing the Deployment Postprocessing setting finally made sure that the symbols were not stripped.

无论在复制期间剥离链接产品和剥离调试符号设置为否,都没有区别 - 只有更改部署后处理设置才能最终确保符号没有被剥离。

回答by alex-i

Same error message, in my case I wasn't linking one of the classes that were needed during the tests.

同样的错误消息,就我而言,我没有链接测试期间所需的类之一。

回答by Dan Poltawski

I discovered my problem was that I had 'Link time optimisation' enabled on my debug build. Setting it to no resolved the problem.

我发现我的问题是我的调试版本启用了“链接时间优化”。将其设置为 no 解决了问题。

回答by tjh

We were using nodejs-mobilewhich would build with the app but fail building with the tests.

我们使用的是nodejs-mobile,它可以与应用程序一起构建,但无法通过测试构建。

Undefined symbols for architecture x86_64:
  _start_node

In addition to all of the previous answers (build settings, search paths, making a brand new Unit Test, deleting DerivedData), what finally resolved it was creating a brand new new UI test instead of a Unit Test in Xcode.

除了之前的所有答案(构建设置、搜索路径、制作全新的单元测试、删除 DerivedData)之外,最终解决的是在 Xcode 中创建一个全新的 UI 测试而不是单元测试。

It built successfully. Then you can copy your test definitions from your current test to the one one.

它构建成功。然后您可以将您的测试定义从当前测试复制到一个。

If you do not need the UI part, you can uncomment XCUIApplication().launch()in setUpof the generated tests, which makes it run as fast as before.

如果你不需要的UI部分,你可以取消XCUIApplication().launch()setUp生成的测试中,这使得它运行的速度是以前的。