Tuesday, February 18, 2014

iOS7 TDD w/ OCMock and Xcode5 Linker problem: -ObjC

I'm setting up a new project, using CocoaPods and a couple of libraries (TestFlight, OCMock, AFNetworking, et al). While CocoaPods may not work well with private repos among public repos, I find it quite useful, especially if someone else wants to join my project quickly.

The biggest pain points I had were linking, which means unless I know in advance that linkers need to be forced for each individual library, I'll get some obtuse error, like:

ld: file not found: -ObjC
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What that really means is I needed to update the flag in my specific project to  -all_load.

Know how to do that? I didn't originally, but finally figured it out. Under the specific project I'm targeting (my tests in this case), in Build Settings -> Linking, I look for the "Other Linker Flags" and make 1 teensy change:

remove '-force_load'
add '-all_load'

That's it!

Oh, and if you're referencing any old OCMock tutorials, please don't use SenTestingKit.framework. You don't even need a header file for test. Just use the following inside your main class:


Now OCMock works great and my code works. Now to write some tests!

Thanks to this blog's comment for helping: Nick Hart