31
votes

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
I'm having the same problem - did you ever find a resolution?Craig Otis

11 Answers

21
votes

Check your Framework Search Paths in your test target settings. These can be corrupted when adding the XCTest Framework.

Adding XCTest to one of my projects prepended a "/" to the paths causing them to not find the correct version.

17
votes

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"
13
votes

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.

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.

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.

6
votes

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)
5
votes

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.

4
votes

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

3
votes

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.

3
votes

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.

XCode Test Target Image

1
votes

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.

1
votes

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.

Target Membership

0
votes

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