Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode 4 fails to initiate unit tests (with linker error) after I created a new scheme

My unit tests worked fine in xcode4 until I had to create a new schema to compile a package to run on my device for testing.

All I did was creating a new Target and a new Scheme, now I try to run the unit tests and get the following error:

The test bundle at [...]Tests.octest could not be loaded because a link error occurred. It is likely that dyld cannot locate a framework framework or library that the the test bundle was linked against, possibly because the framework or library had an incorrect install path at link time.

What did I break?

like image 238
Haoest Avatar asked Jun 10 '11 05:06

Haoest


4 Answers

Like @Haoest and @Peter DeWeese above's comments to Answer 1 - I had exactly the same problem when I changed the product name.

To fix this for the case where you've renamed the product, you need to go to the Build Settings tab of the test target, and change the Linking section - the Debug and Release bundle loader settings. If you have renamed the product - the directory and name of the application may both be incorrect.

Thanks to both of them for pointing this out - but I thought this alternative fix for this situation deserved a higher profile than a comment.

like image 91
iandotkelly Avatar answered Nov 16 '22 07:11

iandotkelly


I've also run across problems with Xcode 4 after adding a target to an existing project. I eventually figured out that the Xcode DerivedData for the project was damaged. By deleting that data, I caused Xcode to rebuild the data and the project returned to normal. I found the data in my home Library folder (~/Library/Developer/Xcode/DerivedData/).

like image 37
Mr. Berna Avatar answered Nov 16 '22 06:11

Mr. Berna


I tried everything (including the other answers and those noted here http://twobitlabs.com/2011/06/adding-ocunit-to-an-existing-ios-project-with-xcode-4/), but finally found a different solution:

Set Deployment Postprocessing (in the Deployment section of Build Settings) to NO for the Debug target.

Before I did this, the executable was being stripped, and the link would fail with

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_SomeClassUnderTest", referenced from:
      objc-class-ref in SomeTest.o

No matter that Strip Linked Product and Strip Debug Symbols During Copy were set to NO, it made no difference - only changing the Deployment Postprocessing setting finally made sure that the symbols were not stripped.

like image 8
sdsykes Avatar answered Nov 16 '22 07:11

sdsykes


Same error message, in my case I wasn't linking one of the classes that were needed during the tests.

like image 2
alex-i Avatar answered Nov 16 '22 06:11

alex-i