简体   繁体   English

测试目标Xcode 5的XCTest构建错误:

[英]XCTest build errors for test target Xcode 5:

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? 关于如何解决的任何想法?

Check your Framework Search Paths in your test target settings. 检查测试目标设置中的框架搜索路径。 These can be corrupted when adding the XCTest Framework. 添加XCTest Framework时,这些可能会被破坏。

Adding XCTest to one of my projects prepended a "/" to the paths causing them to not find the correct version. 将XCTest添加到我的一个项目中会在路径前面加上“/”,导致它们找不到正确的版本。

None of the above answers worked for me. 上述答案都不适合我。 I did find an answer here in 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... 这使您的所有应用程序类自动可用于您的测试目标...

So, that means: 所以,这意味着:

  • Project Navigator > Select your project Project Navigator>选择您的项目
  • Targets > Select your App (not Tests) 目标>选择您的应用程序(不是测试)
  • Build Settings > Search for "Symbols Hidden By Default" 构建设置>搜索“默认隐藏的符号”
  • "Symbols Hidden By Default" > Change it from "YES" to "NO" “默认隐藏的符号”>将其从“是”更改为“否”

I had the same issue; 我遇到过同样的问题; the problem (for me, at least) was that the FRAMEWORKS_SEARCH_PATHS build setting listed the SDK frameworks folder after the main developer frameworks folder. 问题(对我来说,至少)是FRAMEWORKS_SEARCH_PATHS构建设置在主开发者框架文件夹之后列出了SDK frameworks文件夹。

The frameworks included with Xcode have three separate builds: one for OS X, one for iOS (device), and a third for the iOS Simulator. Xcode中包含的框架有三个独立的构建:一个用于OS X,一个用于iOS(设备),第三个用于iOS模拟器。 The OS X build is in the main developer folder, with the other two being under their respective platform folders. OS X构建位于主开发人员文件夹中,其他两个位于其各自的平台文件夹下。 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. 这里的问题是,如果您没有指定首先搜索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; 注意:有时Xcode的速度有点慢; you'll probably need to delete your build folder (better than just a clean) for this to take effect. 你可能需要删除你的build文件夹(不仅仅是干净)才能生效。

Have the same problem after converting tests from SenTestCase to XCTestCase. 将测试从SenTestCase转换为XCTestCase后遇到同样的问题。 Reverting framework dirs fixed issue: 恢复框架dirs修复问题:

"$(SDKROOT)/Developer/Library/Frameworks" (non-recursive)
"$(DEVELOPER_LIBRARY_DIR)/Frameworks" (non-recursive)

So, for me, what I was missing after trying everything else in this post, was: 所以,对我来说,在这篇文章中尝试了其他所有内容后,我所遗漏的是:

Other Linker Flags: 其他链接器标志:

-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 ...”选项不会自动添加。

I was facing problem while adding sentestingkit framework in xcode 5 . 我在xcode 5中添加sentestingkit框架时遇到了问题。 These settings worked for resolving linker problem. 这些设置用于解决链接器问题。 搜索路径

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 Framework。

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文件,确保打开右侧窗格。

XCode测试目标图像

I had the same problem when tried to build XCTTest-based unit tests with pre-7.0 SDK. 当尝试使用7.0之前的SDK构建基于XCTTest的单元测试时,我遇到了同样的问题。 When I chose 7.0 as my Base SDK then that kind of link error disappeared. 当我选择7.0作为我的Base SDK时,那种链接错误就消失了。

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下检查您的测试文件夹。

目标会员

Make sure that the Search Framework Path ( FRAMEWORK_SEARCH_PATHS ) for the YourProjectTests target includes the path $(SDKROOT)/Developer/Library/Frameworks , and that this one is listed before $(inherited) . 确保YourProjectTests目标的搜索框架路径( FRAMEWORK_SEARCH_PATHS )包含路径$(SDKROOT)/Developer/Library/Frameworks ,并且这个路径在$(inherited)之前列出。

In my case, both paths were present, but $(inherited) was the first one. 就我而言,两条路径都存在,但$(inherited)是第一条路径。

Credit goes to https://stackoverflow.com/users/181947/brian-clear on Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS 感谢Apple Mach-O链接器上的https://stackoverflow.com/users/181947/brian-clear(id )警告:为MacOSX构建,但是为iOS构建的dylib链接

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

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