简体   繁体   English

OCUnit迁移到XCTest会导致链接器错误

[英]Migration of OCUnit to XCTest leads to linker error

I've tried to migrate our OCUnit to XCTest . 我试图将OCUnit迁移到XCTest So I have 100% compilable project but I see next linker error: 所以我有100%可编译的项目,但是我看到下一个链接器错误:

Error:Undefined symbol '_OBJC_CLASS_$_XCTestCase' referenced from:...

My "Framework Search Paths" looks like this: 我的"Framework Search Paths"如下所示:

$(SDKROOT)/Developer/Library/Frameworks     (non-recursive)
$(inherited)                                (non-recursive)
$(DEVELOPER_FRAMEWORKS_DIR)                 (non-recursive)

I'm not familiar what else to do to satisfy linker 我不知道还能做什么来满足链接器的要求

I am seeing the exact same error messages in Xcode 6.1 after migrating with 迁移至Xcode 6.1后,我看到了完全相同的错误消息
Pull Down MenuEditRefactorConvert to XCTest . 下拉菜单编辑重构转换为XCTest

I got 2 solutions: 我有2个解决方案:


Solution 1 (recreate test project) 解决方案1 (重新创建测试项目)

  1. Backup all source files in your test project. 备份测试项目中的所有源文件。

  2. In Project Navigator , select the project. 项目浏览器中 ,选择项目。
    This shows the project settings. 这显示了项目设置。

  3. In the project settings, click Show project and targets list . 在项目设置中,单击显示项目和目标列表 显示项目和目标清单

  4. Select the test target , and press delete to delete it. 选择测试目标 ,然后按Delete其删除。 项目设置-测试目标

  5. In Project Navigator , select the test target , and press delete to delete it. Project Navigator中 ,选择测试目标 ,然后按Delete其删除。 项目导航器-测试目标

  6. In Test Navigator , click the + button on the bottom left, and choose New Test Target . 在“ 测试导航器”中 ,单击左下角的+按钮,然后选择新建测试目标 测试导航器-新的测试目标

  7. Add your original source files back into the new test target. 将原始源文件重新添加到新的测试目标中。

  8. Now test your project as usual. 现在像往常一样测试您的项目。


Solution 2 (hackishly modify test project) 解决方案2 (修改测试项目)

  1. In Project Navigator , select the project. 项目浏览器中 ,选择项目。
    This shows the project settings. 这显示了项目设置。

  2. In the project settings, select the test target (not the main target), then select Build Phases . 在项目设置中,选择测试目标 (不是主要目标),然后选择Build Phases

  3. In Link Binary With Libraries , click the + button. “将二进制文件与库链接”中 ,单击+按钮。
    This shows the list of frameworks, but there is no XCTest. 这显示了框架列表,但是没有XCTest。

  4. Choose a framework that you don't use at all, say, Twitter.framework , and click Add . 选择一个根本不用的框架,例如Twitter.framework ,然后单击“ 添加”

  5. Open your project file ( something.pbxproj ) in a text editor, and replace all occurrences of Twitter.framework with XCTest.framework . 在文本编辑器中打开您的项目文件( something.pbxproj ),并将所有出现的Twitter.framework替换为XCTest.framework
    Note: the pbxproj file is inside the .xcodeproj folder. 注意: pbxproj文件位于.xcodeproj文件夹内。 In Finder, you have to right click on the .xcodeproj and select Show Package Contents . 在Finder中,您必须右键单击 .xcodeproj,然后选择显示包内容

  6. Go back to Link Binary With Libraries in Xcode, and check that XCTest.framework is added. 返回到Xcode中的使用库链接二进制文件 ,并检查是否已添加XCTest.framework

    • If not, try restarting Xcode. 如果不是,请尝试重新启动Xcode。
    • If it is added but is red, just ignore it. 如果已添加但为红色,则忽略它。 Xcode can't find the framework, but the linker can. Xcode找不到框架,但是链接器可以找到。
  7. Now test your project as usual. 现在像往常一样测试您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM