I have set up an XCode 5 iOS 7 project for unit tests.
我已经为单元测试建立了XCode 5 ios7项目。
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?
有什么办法解决吗?
11 个解决方案
#1
21
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,会在路径前面加上“/”,导致它们找不到正确的版本。
#2
15
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...
对于在应用程序中查找类的链接错误…将“默认隐藏的符号”设置为app目标中的“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"
- "默认隐藏的符号" >将它从"是"改为"否"
#3
13
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框架文件夹。
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构建在主开发人员文件夹中,另外两个在各自的平台文件夹下。这里的问题是,如果不指定首先搜索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理解起来有点慢;您可能需要删除构建文件夹(比只删除一个要好)以使其生效。
#4
6
Have the same problem after converting tests from SenTestCase to XCTestCase. Reverting framework dirs fixed issue:
在将测试从SenTestCase转换为XCTestCase之后,会出现同样的问题。恢复框架dirs固定问题:
"$(SDKROOT)/Developer/Library/Frameworks" (non-recursive)
"$(DEVELOPER_LIBRARY_DIR)/Frameworks" (non-recursive)
#5
5
So, for me, what I was missing after trying everything else in this post, was:
所以,对我来说,我在尝试了其他所有的东西后,失去了什么,是:
Other Linker Flags:
其它的链接器标志:
-framework XCTest
框架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(带有ios8 SDK),所以我很惊讶“编辑>重构>到XCTest…”选项没有自动添加这个选项。
#6
4
I was facing problem while adding sentestingkit framework in xcode 5 . These settings worked for resolving linker problem.
我在xcode 5中添加sentestingkit框架时遇到了问题。这些设置用于解决链接器问题。
#7
3
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框架。
#8
3
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文件,确保打开了正确的窗格。
#9
1
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.
在尝试使用pre-7.0 SDK构建基于xcttest的单元测试时,我遇到了同样的问题。当我选择7.0作为我的基本SDK时,那种链接错误就消失了。
#10
1
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,并确保在目标成员关系下只检查您的测试文件夹。
#11
0
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/Framework,并且这个路径在$(继承)之前列出。
In my case, both paths were present, but $(inherited)
was the first one.
在我的例子中,两种路径都存在,但是$(继承)是第一个路径。
Credit goes to https://*.com/users/181947/brian-clear on Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS
信用转到https://*.com/users/181947/brian-clear上的苹果Mach-O链接器(id)警告:为MacOSX构建,但链接到为iOS构建的dylib
#1
21
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,会在路径前面加上“/”,导致它们找不到正确的版本。
#2
15
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...
对于在应用程序中查找类的链接错误…将“默认隐藏的符号”设置为app目标中的“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"
- "默认隐藏的符号" >将它从"是"改为"否"
#3
13
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框架文件夹。
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构建在主开发人员文件夹中,另外两个在各自的平台文件夹下。这里的问题是,如果不指定首先搜索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理解起来有点慢;您可能需要删除构建文件夹(比只删除一个要好)以使其生效。
#4
6
Have the same problem after converting tests from SenTestCase to XCTestCase. Reverting framework dirs fixed issue:
在将测试从SenTestCase转换为XCTestCase之后,会出现同样的问题。恢复框架dirs固定问题:
"$(SDKROOT)/Developer/Library/Frameworks" (non-recursive)
"$(DEVELOPER_LIBRARY_DIR)/Frameworks" (non-recursive)
#5
5
So, for me, what I was missing after trying everything else in this post, was:
所以,对我来说,我在尝试了其他所有的东西后,失去了什么,是:
Other Linker Flags:
其它的链接器标志:
-framework XCTest
框架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(带有ios8 SDK),所以我很惊讶“编辑>重构>到XCTest…”选项没有自动添加这个选项。
#6
4
I was facing problem while adding sentestingkit framework in xcode 5 . These settings worked for resolving linker problem.
我在xcode 5中添加sentestingkit框架时遇到了问题。这些设置用于解决链接器问题。
#7
3
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框架。
#8
3
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文件,确保打开了正确的窗格。
#9
1
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.
在尝试使用pre-7.0 SDK构建基于xcttest的单元测试时,我遇到了同样的问题。当我选择7.0作为我的基本SDK时,那种链接错误就消失了。
#10
1
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,并确保在目标成员关系下只检查您的测试文件夹。
#11
0
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/Framework,并且这个路径在$(继承)之前列出。
In my case, both paths were present, but $(inherited)
was the first one.
在我的例子中,两种路径都存在,但是$(继承)是第一个路径。
Credit goes to https://*.com/users/181947/brian-clear on Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS
信用转到https://*.com/users/181947/brian-clear上的苹果Mach-O链接器(id)警告:为MacOSX构建,但链接到为iOS构建的dylib