ios 测试目标 Xcode 5 的 XCTest 构建错误:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18266649/
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
XCTest build errors for test target Xcode 5:
提问by user798719
I have set up an XCode 5 iOS 7 project for unit tests.
我已经为单元测试设置了一个 XCode 5 iOS 7 项目。
Of course, setting up the unit tests are taking me so long that I'm trying to keep the faith that it's worth it. Struggling for hours over this error:
当然,设置单元测试花费了我很长时间,以至于我一直坚信它是值得的。为这个错误挣扎了几个小时:
ld: building for iOS Simulator, but linking against dylib built for MacOSX file
'/Applications/Xcode5-DP5.app/Contents/Developer/Library/Frameworks/XCTest.framework/XCTest'
for architecture i386
Any ideas on how to solve?
关于如何解决的任何想法?
回答by HatAndBeard
Check your Framework Search Paths in your test target settings. These can be corrupted when adding the XCTest Framework.
检查测试目标设置中的框架搜索路径。添加 XCTest 框架时,这些可能会损坏。
Adding XCTest to one of my projects prepended a "/" to the paths causing them to not find the correct version.
将 XCTest 添加到我的一个项目中,在路径前面加上了一个“/”,导致它们找不到正确的版本。
回答by eckyzero
None of the above answers worked for me. I did find an answer herein a comment left by Tim Macfarlane.
以上答案都不适合我。我没有找到答案,在这里由蒂姆·麦克法兰留下评论。
For linker errors looking for a class in your app... set the “Symbols Hidden by Default” build setting to “NO” in your app target. This makes all your app classes available to your test target automatically...
对于在您的应用程序中查找类的链接器错误...在您的应用程序目标中将“Symbols Hidden by Default”构建设置设置为“NO”。这使您的所有应用程序类都可自动用于您的测试目标...
So, that means:
所以,这意味着:
- Project Navigator > Select your project
- Targets > Select your App (not Tests)
- Build Settings > Search for "Symbols Hidden By Default"
- "Symbols Hidden By Default" > Change it from "YES" to "NO"
- 项目导航器 > 选择您的项目
- 目标 > 选择您的应用程序(不是测试)
- 构建设置 > 搜索“默认隐藏的符号”
- “默认隐藏符号”> 将其从“是”更改为“否”
回答by Calrion
I had the same issue; the problem (for me, at least) was that the FRAMEWORKS_SEARCH_PATHS
build setting listed the SDK frameworks folder afterthe main developer frameworks folder.
我遇到过同样的问题; 问题(至少对我而言)是FRAMEWORKS_SEARCH_PATHS
构建设置在主开发人员框架文件夹之后列出了 SDK 框架文件夹。
The frameworks included with Xcode have three separate builds: one for OS X, one for iOS (device), and a third for the iOS Simulator. The OS X build is in the main developer folder, with the other two being under their respective platform folders. The rub here is that if you don't specify to search the SDK folders first (which are within the platform folders), Xcode (or more correctly, the linker) will find the OS X build first and produce the error you see.
Xcode 包含的框架具有三个独立的构建版本:一个用于 OS X,一个用于 iOS(设备),第三个用于 iOS 模拟器。OS X 版本位于主 developer 文件夹中,另外两个位于各自的平台文件夹下。这里的问题是,如果您没有指定首先搜索 SDK 文件夹(位于平台文件夹内),Xcode(或更准确地说,链接器)将首先找到 OS X 构建并产生您看到的错误。
The solution is simple, put:
解决方法很简单,把:
FRAMEWORK_SEARCH_PATHS = $(SDKROOT)/Developer/Library/Frameworks $(inherited)
in your build settings. If you're putting build settings in the project file (I don't recommend it, but that's another question for another day), it's just named "Framework search paths."
在您的构建设置中。如果您将构建设置放在项目文件中(我不推荐这样做,但这是另一天的另一个问题),它只是命名为“框架搜索路径”。
NOTE: Sometimes Xcode's a little slow to catch on; you'll probably need to delete your build
folder (better than just a clean) for this to take effect.
注意:有时 Xcode 有点难以理解;您可能需要删除您的build
文件夹(不仅仅是一个干净的文件夹)才能使其生效。
回答by Aist Marabu
Have the same problem after converting tests from SenTestCase to XCTestCase. Reverting framework dirs fixed issue:
将测试从 SenTestCase 转换为 XCTestCase 后遇到同样的问题。恢复框架目录修复了问题:
"$(SDKROOT)/Developer/Library/Frameworks" (non-recursive)
"$(DEVELOPER_LIBRARY_DIR)/Frameworks" (non-recursive)
回答by Ryan H.
So, for me, what I was missing after trying everything else in this post, was:
所以,对我来说,在尝试了这篇文章中的其他所有内容后,我缺少的是:
Other Linker Flags:
其他链接器标志:
-framework XCTest
-framework XCTest
I'm currently using Xcode 6.0 (with the iOS 8 SDK) so I'm surprised that the "Edit > Refactor > Convert to XCTest..." option doesn't add this automatically.
我目前正在使用 Xcode 6.0(带有 iOS 8 SDK),所以我很惊讶“编辑 > 重构 > 转换为 XCTest...”选项没有自动添加。
回答by Muhammad Adnan
I was facing problem while adding sentestingkit framework in xcode 5 . These settings worked for resolving linker problem.
我在 xcode 5 中添加 sentestingkit 框架时遇到了问题。这些设置用于解决链接器问题。
回答by ribeto
I had the same issue after renaming my Target name and moving things around. It turned out that my tests were part of my Main Target. Make sure that you all your test files belong only to your test target.
重命名我的目标名称并移动内容后,我遇到了同样的问题。结果证明我的测试是我的主要目标的一部分。确保您所有的测试文件只属于您的测试目标。
Just select a .m file, make sure you have the right pane open.
只需选择一个 .m 文件,确保您打开了右侧窗格。
回答by cnnrdltn
I had this problem upon adding another file for tests. If you do this with (CMD + N) be sure to only target the Test Bundle (ie. 'AppNameTests').
我在添加另一个文件进行测试时遇到了这个问题。如果您使用 (CMD + N) 执行此操作,请确保仅针对测试包(即“AppNameTests”)。
I guess only these .xctest bundles have access to the XCTest Framework.
我猜只有这些 .xctest 包可以访问 XCTest 框架。
回答by Pavel Osipov
I had the same problem when tried to build XCTTest-based unit tests with pre-7.0 SDK. When I chose 7.0 as my Base SDK then that kind of link error disappeared.
尝试使用 7.0 之前的 SDK 构建基于 XCTTest 的单元测试时,我遇到了同样的问题。当我选择 7.0 作为我的基础 SDK 时,那种链接错误就消失了。
回答by Bob
Had a the same issue but ended up with a slightly different solution.
有同样的问题,但最终得到了略有不同的解决方案。
select XCTest.framework and make sure that only your test folder is checked under Target Membership.
选择 XCTest.framework 并确保在 Target Membership 下只选中您的 test 文件夹。