XCTest build errors for test target Xcode 5:
Asked Answered
S

11

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?

Sisak answered 16/8, 2013 at 5:52 Comment(1)
I'm having the same problem - did you ever find a resolution?Lapboard
H
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.

Hultin answered 21/9, 2013 at 13:10 Comment(2)
Removing the 2 occurrences of (\") make it works for me, Thanks!Anjaanjali
Thank you, and great spot! Unwanted string-escaping, introduced by XCode, was the issue.Houseclean
O
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"
Oldworld answered 24/6, 2014 at 15:28 Comment(6)
Did you mean "Change it from YES to NO"? Nothing has worked for me, not even this :-(Macias
Good eye. I made the correction. If this doesn't solve the problem, I don't know what would :(Oldworld
Did you see my other response in this thread about the other linker flags? That's that final piece that I was missing. I did NOT need all those other search paths that others have added.Macias
Great follow-through @RyanH. Thanks!Oldworld
I just changed for DEBUG only, and it solved the linking issue with classes compiled only in hosting app.Whenas
I also had to set Deployment Postprocessing to NO for DebugVictim
L
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.

Lubricator answered 9/11, 2013 at 7:31 Comment(1)
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.Vault
I
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)
Immoderacy answered 6/12, 2013 at 12:32 Comment(2)
Million upvotes if I could. This was the fix for me.Doc
Yup, also fixed this for me. Thanks!Raggletaggle
M
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.

Macias answered 21/9, 2014 at 0:41 Comment(1)
Yup, that worked for me, thanks! Bizarre that the conversion misses this out!Munt
D
4

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

Desmonddesmoulins answered 9/4, 2014 at 10:10 Comment(2)
This works but I get some "directory not found" errors. Afraid it can cause problems laterWallack
can you post which directory not found .Snapshot or complete path ?Desmonddesmoulins
G
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.

Gerome answered 25/8, 2013 at 4:52 Comment(0)
O
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

Overcheck answered 16/5, 2014 at 20:51 Comment(1)
woohoo! nice! thanks for posting this. it solved my problem.Eckel
S
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.

Shelves answered 9/10, 2013 at 8:44 Comment(0)
D
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

Davit answered 3/8, 2014 at 0:55 Comment(0)
C
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

Corelative answered 3/4, 2014 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.