XCTest build errors for test target Xcode 5:

2019-01-17 15:00发布

I have set up an XCode 5 iOS 7 project for unit tests.

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条回答
神经病院院长
2楼-- · 2019-01-17 15:01

Have the same problem after converting tests from SenTestCase to XCTestCase. Reverting framework dirs fixed issue:

"$(SDKROOT)/Developer/Library/Frameworks" (non-recursive)
"$(DEVELOPER_LIBRARY_DIR)/Frameworks" (non-recursive)
查看更多
看我几分像从前
3楼-- · 2019-01-17 15:02

I was facing problem while adding sentestingkit framework in xcode 5 . These settings worked for resolving linker problem.Search Paths

查看更多
聊天终结者
4楼-- · 2019-01-17 15:06

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.

查看更多
贪生不怕死
5楼-- · 2019-01-17 15:10

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
  • Targets > Select your App (not Tests)
  • Build Settings > Search for "Symbols Hidden By Default"
  • "Symbols Hidden By Default" > Change it from "YES" to "NO"
查看更多
女痞
6楼-- · 2019-01-17 15:16

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).

In my case, both paths were present, but $(inherited) was the first one.

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

查看更多
劳资没心,怎么记你
7楼-- · 2019-01-17 15:17

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').

I guess only these .xctest bundles have access to the XCTest Framework.

查看更多
登录 后发表回答