0

I am getting an error :

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

Detailed error :

Ld /Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Products/Debug-iphonesimulator/RideShareBuddyTests.app/RideShareBuddyTests normal i386
cd "/Users/akashpatel/Documents/iOS development/RideShare/RideShare"
setenv IPHONEOS_DEPLOYMENT_TARGET 6.1
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk -L/Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Products/Debug-iphonesimulator "-L/Users/akashpatel/Documents/iOS development/RideShare/RideShare/RideShare" -F/Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Products/Debug-iphonesimulator "-F/Users/akashpatel/Documents/iOS development/RideShare/RideShare" -filelist /Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Intermediates/RideShareBuddy.build/Debug-iphonesimulator/RideShareBuddyTests.build/Objects-normal/i386/RideShareBuddyTests.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -ObjC -all_load -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.1 -framework QuartzCore -framework GHUnitIOS -framework UIKit -framework Foundation -framework CoreGraphics -lOCMock -o /Users/akashpatel/Library/Developer/Xcode/DerivedData/RideShareBuddy-cqfdiphwubeiexdigypzpjjfqaiy/Build/Products/Debug-iphonesimulator/RideShareBuddyTests.app/RideShareBuddyTests

I don't have duplicate files in Compile Sources.

Ask if more details is required.

EDIT :

#import <GHUnitIOS/GHUnit.h>
#import "OCMock.h"
#import "RS_LoginRSViewController.h"

@interface RS_LoginRSViewControllerTest : GHTestCase
{
    RS_LoginRSViewController * loginObject;
}
@end

@implementation RS_LoginRSViewControllerTest

// Run before each test method
- (void)setUp { }

// Run after each test method
- (void)tearDown { }

// Run before the tests are run for this class
- (void)setUpClass
{
    loginObject = [[RS_LoginRSViewController alloc] init];
    GHAssertNotNil(loginObject, @"Could not create test object.");
}

// Run before the tests are run for this class
- (void)tearDownClass { }

- (void)testViewDidLoad
{
    GHTestLog(@"Log with a test with the GHTestLog(...) for test specific logging.");
}

@end

Added a path in Library search path and Header search path. It raised one more error.

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_RS_LoginRSViewController", referenced from:
      objc-class-ref in RS_LoginRSViewControllerTest.o
     (maybe you meant: _OBJC_CLASS_$_RS_LoginRSViewControllerTest)
Geek
  • 8,280
  • 17
  • 73
  • 137
  • have u added the all the required frameworks correctly?..have u added libz.dylib? – Master Stroke Aug 13 '13 at 08:05
  • I just integrated GHUnit and OCMock. Just starting for first test class. Followed all steps on http://www.raywenderlich.com/3716/unit-testing-in-xcode-4-quick-start-guide. I was facing a problem while integrating OCMock that `#import ` was giving error. I changed it to `#import "OCMock.h"` and error went away. I don't know if that is causing problem now. – Geek Aug 13 '13 at 08:10
  • I suspect the same, looks like your missing a critical framework. – khanh.tran.vinh Aug 13 '13 at 08:10
  • @khanh.tran.vinh I have added framework.May be problem is something else. – Geek Aug 13 '13 at 08:17
  • I am posting code for unit testing if it has anything wrong. – Geek Aug 13 '13 at 08:20
  • change the header search path in the build settings... – Master Stroke Aug 13 '13 at 08:20
  • @PKCoder After posting this question I added path and it raised one more error `Undefined symbols for architecture i386: "_OBJC_CLASS_$_RS_LoginRSViewController", referenced from: objc-class-ref in RS_LoginRSViewControllerTest.o (maybe you meant: _OBJC_CLASS_$_RS_LoginRSViewControllerTest)`. – Geek Aug 13 '13 at 08:41
  • @Akash... go through this http://stackoverflow.com/questions/14157632/undefined-symbols-for-architecture-i386-objc-class-zipexception-reference – Master Stroke Aug 13 '13 at 09:00

2 Answers2

0

I don't want to drag the comments section as its already reached the limit..I suspect the way you're importing the third party framework such as OCMock is wrong...

As you have already downloaded the sample from raywenderlich,just compare its builsettings section with your actual project...

Check these link1 and link2..Moreover its a possible duplicate of what you're looking for...

Community
  • 1
  • 1
Master Stroke
  • 5,108
  • 2
  • 26
  • 57
  • One more update. Using this http://ocmock.org/ios/ I modified `Other Linker Flags` and that removed error of undefined symbol. Currently only error I am facing is `ld: file not found: -fobjc-arc clang: error: linker command failed with exit code 1 (use -v to see invocation)`. – Geek Aug 13 '13 at 09:14
  • As he notes I added `RS_LoginRSViewController.m` file in target for tests. But same problem. – Geek Aug 13 '13 at 09:26
0

First I needed to set Library search path and Header search path as shown in Adding OCMock->step 3 in this link.

After that to solve my Undefined symbol error, I had to add all classes to test target. To see how to add files to a specific target, look at SO question.

Community
  • 1
  • 1
Geek
  • 8,280
  • 17
  • 73
  • 137