XCTest build errors for test target Xcode 5:

24,452

Solution 1

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.

Solution 2

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"

Solution 3

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.

Solution 4

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)

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

Share:
24,452
user798719
Author by

user798719

Some questions may end up being dumb, but if I ask it, it's not dumb to me.

Updated on September 23, 2020

Comments

  • user798719
    user798719 almost 4 years

    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?

  • Olivier Amblet
    Olivier Amblet over 10 years
    Removing the 2 occurrences of (\") make it works for me, Thanks!
  • karim
    karim over 10 years
    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.
  • Chris Hatton
    Chris Hatton over 10 years
    Thank you, and great spot! Unwanted string-escaping, introduced by XCode, was the issue.
  • buildsucceeded
    buildsucceeded over 10 years
    Million upvotes if I could. This was the fix for me.
  • yan.kun
    yan.kun about 10 years
    Yup, also fixed this for me. Thanks!
  • Michal Shatz
    Michal Shatz about 10 years
    This works but I get some "directory not found" errors. Afraid it can cause problems later
  • Muhammad Adnan
    Muhammad Adnan about 10 years
    can you post which directory not found .Snapshot or complete path ?
  • Ryan H.
    Ryan H. almost 10 years
    Did you mean "Change it from YES to NO"? Nothing has worked for me, not even this :-(
  • ebandersen
    ebandersen almost 10 years
    Good eye. I made the correction. If this doesn't solve the problem, I don't know what would :(
  • Ryan H.
    Ryan H. almost 10 years
    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.
  • ebandersen
    ebandersen almost 10 years
    Great follow-through @RyanH. Thanks!
  • Andy
    Andy over 9 years
    Yup, that worked for me, thanks! Bizarre that the conversion misses this out!
  • ıɾuǝʞ
    ıɾuǝʞ over 9 years
    I just changed for DEBUG only, and it solved the linking issue with classes compiled only in hosting app.
  • Julian A.
    Julian A. over 8 years
    woohoo! nice! thanks for posting this. it solved my problem.
  • funkybro
    funkybro almost 8 years
    I also had to set Deployment Postprocessing to NO for Debug