31

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?

Yaakov Ellis
  • 40,752
  • 27
  • 129
  • 174
user798719
  • 9,619
  • 25
  • 84
  • 123

11 Answers11

21

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.

HatAndBeard
  • 1,416
  • 3
  • 18
  • 31
17

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"
ebandersen
  • 2,362
  • 26
  • 25
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.

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.

Calrion
  • 3,202
  • 1
  • 28
  • 30
  • Only this answer worked for me. I have all the path and settings ok, but the order really matters. I was using SenTestingKit. Searched for solution for couple of hours and lastly found it. – karim Jan 13 '14 at 14:40
6

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)
Kjuly
  • 34,476
  • 22
  • 104
  • 118
Aist Marabu
  • 169
  • 2
  • 9
5

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.

Ryan H.
  • 7,374
  • 4
  • 39
  • 46
4

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

Muhammad Adnan
  • 2,668
  • 15
  • 27
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').

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

cnnrdltn
  • 31
  • 2
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.

XCode Test Target Image

ribeto
  • 2,038
  • 1
  • 16
  • 17
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.

Pavel Osipov
  • 2,067
  • 1
  • 19
  • 27
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.

Target Membership

Bob
  • 993
  • 2
  • 10
  • 21
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).

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

Community
  • 1
  • 1
Marius
  • 3,589
  • 3
  • 27
  • 30