3

I am using OCMock (version 3.1.1) in my project and I am trying to use the OCMVerify macro to check if some method is called inside my object.

The problem is when I put this line:

OCMVerify([mockEngine notify]);

XCode show me the following link error (I've tried all platforms though):

Undefined symbols for architecture i386:
  "OCMMakeLocation(objc_object*, char const*, int)", referenced from:
      -[T009_EngineTest testPostEvent] in T009_EngineTest.o
ld: symbol(s) not found for architecture i386

I took the last version of the library from the website and I've also tried to compile it by myself.

Here is the unit test code:

Engine *mockEngine = OCMClassMock([Engine class]);
Object *obj = [[Object alloc] init];

[mockEngine startUp];
[mockEngine run];
[mockEngine postEvent:obj];

[NSThread sleepForTimeInterval:0.5];

OCMVerify([mockEngine notify]);   // << THIS LINE CREATES THE LINK PROBLEM..

[mockEngine shutDown];

If I comment that line, the compiler links successfully.. It seems that that symbol is not in the library binary but I checked it was in the Xcode Compile Sources list. Then I did a workaround... I hardcoded this line (the original code from the OCMock) into my unit test file:

OCMLocation *OCMMakeLocation(id testCase, const char *fileCString, int line){
    return [OCMLocation locationWithTestCase:testCase file:[NSString     stringWithUTF8String:fileCString] line:line];
}

And it works! Now I want to know if there is some bug in OCMock or am I doing something wrong!

Here is the original header file declaring the external OCMakeLocation function: https://github.com/erikdoe/ocmock/blob/master/Source/OCMock/OCMLocation.h and here its implementation: https://github.com/erikdoe/ocmock/blob/master/Source/OCMock/OCMLocation.m

Thanks.

  • If you expand the library, do you see OCMLocation.o? I've found that sometimes the compiler optimizes code out of libraries. – Ben Flynn Sep 01 '14 at 02:15
  • I used "nm -oa" and greped Location and there are many symbols, but here are the MakeLocation ones: libOCMock.a:OCMLocation.o: 00000000000001e0 T _OCMMakeLocation libOCMock.a:OCMLocation.o: 00000000000012b8 S _OCMMakeLocation.eh – Christian Hess Sep 02 '14 at 18:06
  • I got the same error when use the OCMock, your 'hardcode' solution just works fine for me. :) – JerryZhou Sep 29 '14 at 02:09
  • possible duplicate of [OCMock 3.0.2 linker error with .mm test file](http://stackoverflow.com/questions/24928605/ocmock-3-0-2-linker-error-with-mm-test-file) – Keith Feb 24 '15 at 21:21
  • This great answer fixed it for me: http://stackoverflow.com/a/26782920/2828256 – AShavit Nov 10 '15 at 15:57

0 Answers0