Xcode 不会将 XCTest 链接到 iOSSimulator 版本
Posted
技术标签:
【中文标题】Xcode 不会将 XCTest 链接到 iOSSimulator 版本【英文标题】:Xcode will not link XCTest to the iOSSimulator version 【发布时间】:2015-03-31 02:05:38 【问题描述】:因此,对于我的一个课程,我们应该从上一季度开始重构这个处于非常糟糕状态的项目。
所以我们正在尝试为项目编写单元测试,但他们使用的是旧版本的 Xcode,因此我们不得不将 XCTest 框架重新添加到“Link Binary With Libraries”中。
我第一次不小心添加了它的 MacOSX 版本,并注意到我的错误。我从链接器中删除了 OS X 版本,并向其中添加了 iPhoneSimulator 版本。它一直给我同样的错误。所以我从构建阶段删除了所有 XCTest.framework 文件,它给了我一个关于 OCMock 的错误(这是一个完全不同的问题,我现在并不关心),这意味着它知道它已经消失了。所以我然后尝试将 XCTest.framework 重新添加到我的测试目标中,确保它是 iosSimulator 版本,并且它给了我关于它是 Mac OS X 版本的相同错误。我已经尝试重新启动 Xcode 并正确执行了我之前所做的操作,但没有成功。以下是错误的完整输出。
Ld /Users/MY_USERNAME/Library/Developer/Xcode/DerivedData/Henry-ayqkhtmgjufxaagawvfjprhgilji/Build/Products/Debug-iphonesimulator/HenryTests.xctest/HenryTests normal x86_64
cd /Users/MY_USERNAME/Git/JrProj-1415-Mike/Code/iOS/Henry
export IPHONEOS_DEPLOYMENT_TARGET=7.1
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.2.sdk -L/Users/MY_USERNAME/Library/Developer/Xcode/DerivedData/Henry-ayqkhtmgjufxaagawvfjprhgilji/Build/Products/Debug-iphonesimulator -L/Users/MY_USERNAME/Git/JrProj-1415-Mike/Code/iOS/Henry -F/Users/MY_USERNAME/Library/Developer/Xcode/DerivedData/Henry-ayqkhtmgjufxaagawvfjprhgilji/Build/Products/Debug-iphonesimulator -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.2.sdk/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks -F/Users/MY_USERNAME/Git/JrProj-1415-Mike/Code/iOS/Henry -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.2.sdk/Developer/Library/Frameworks -filelist /Users/MY_USERNAME/Library/Developer/Xcode/DerivedData/Henry-ayqkhtmgjufxaagawvfjprhgilji/Build/Intermediates/Henry.build/Debug-iphonesimulator/HenryTests.build/Objects-normal/x86_64/HenryTests.LinkFileList -bundle_loader /Users/MY_USERNAME/Library/Developer/Xcode/DerivedData/Henry-ayqkhtmgjufxaagawvfjprhgilji/Build/Products/Debug-iphonesimulator/Henry.app/Henry -Xlinker -objc_abi_version -Xlinker 2 -framework XCTest -ObjC -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.1 -framework XCTest -lOCMock -framework UIKit -framework Foundation -framework Firebase -Xlinker -dependency_info -Xlinker /Users/MY_USERNAME/Library/Developer/Xcode/DerivedData/Henry-ayqkhtmgjufxaagawvfjprhgilji/Build/Intermediates/Henry.build/Debug-iphonesimulator/HenryTests.build/Objects-normal/x86_64/HenryTests_dependency_info.dat -o /Users/MY_USERNAME/Library/Developer/Xcode/DerivedData/Henry-ayqkhtmgjufxaagawvfjprhgilji/Build/Products/Debug-iphonesimulator/HenryTests.xctest/HenryTests
ld: building for iOS Simulator, but linking against dylib built for MacOSX file '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework/XCTest' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
【问题讨论】:
【参考方案1】:如果有人也遇到这个问题,几乎唯一的解决方案是创建一个新项目,并将所有文件添加到该新项目中。我与一些 iOS 开发专业人士交谈过,他们想不出其他解决方案。我认为这与来自相当旧版本的 Xcode 的项目有关,而新的 XCTest 框架相当新。如果你也遇到这种情况,祝你好运。
【讨论】:
以上是关于Xcode 不会将 XCTest 链接到 iOSSimulator 版本的主要内容,如果未能解决你的问题,请参考以下文章
iOS:xcode 5,将项目从 xctest 迁移到 senTestingKit
可以将 C++ 单元测试集成到 Xcode 的 XCTest 中吗?