"_OBJC_CLASS_$_viewsampleViewController", referenced from:
i create a view controller viewsampleViewController.. And it has two method setname and getname.. i create a testcase for that view controller. my testcase name is newTestCase and method name is testName.
#import "newTestCase.h"
#import "viewsampleViewController.h"
@implementation newTestCase
in my testName method,
-(void)testName{
NSString *b=@"hell开发者_如何学编程o";
v =[[viewsampleViewController alloc] init];
STAssertNotNil(v,@"v doesnt created");
[v setuname:@"hello"];
NSString *a=[v getuname];
STAssertEquals(b,a,@"error:name not equal");
[v release];
}
-(void)setUp{
v=[viewsampleViewController alloc];
}
-(void) tearDown{
[v release];
}
when i build i got an error
Ld "build/Debug-iphoneos/Unit test.octest/Unit test" normal armv6
cd /Users/anande/Documents/viewsample
setenv IPHONEOS_DEPLOYMENT_TARGET 3.1.3
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -bundle -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk -L/Users/anande/Documents/viewsample/build/Debug-iphoneos -F/Users/anande/Documents/viewsample/build/Debug-iphoneos -F/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/Developer/Library/Frameworks -filelist "/Users/anande/Documents/viewsample/build/viewsample.build/Debug-iphoneos/Unit test.build/Objects-normal/armv6/Unit test.LinkFileList" -dead_strip -framework Foundation -framework SenTestingKit -miphoneos-version-min=3.1.3 -o "/Users/anande/Documents/viewsample/build/Debug-iphoneos/Unit test.octest/Unit test"
Undefined symbols:
"_OBJC_CLASS_$_viewsampleViewController", referenced from:
__objc_classrefs__DATA@0 in newTestCase.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
plz help me,
This linker problem appears because of architecture and dependency.Actually when we add some files to our project from some other sources then there may not establish the exact dependency.So compiler generates the linker error.I solved this problem by following the steps:
- Select Target
- Select build phases
- Select compile sources
- Choose + icon
- Select the .m file for which you are getting error and add it.
- Clean the build and run again.
This is a Linker error, add viewsampleViewController.m to your test target. Please start your class names uppercase, makes everything a lot more readable
Somehow the viewsampleViewController.m file is not being compiled. Make sure its part of the project.
I had the same problem, in my doing some changes on the sources of the project. All the .m were changed to .mm and for some reason in the 'Link Binary With Libraries' the specific class that was having problems wasn't added there, but was in 'Copy Bundle Resources'. After I changed that it worked.
So this is what i did:
1) Click on the blue project tab on the upper-left side of Xcode. 2) Go to the 'TARGETS' option. 3) Go to 'Build Phases' Tab. 4) Go to 'Copy Bundle Resources'. 5) Look for the implementation file (.m, .mm) and if it's there remove it by clicking on the minus (-) option. 6) Go to 'Compile Sources' and click on the plus (+) option and add that implementation file. 7) Compile and hit it, brother, you're good to go.
Hope this helps. Cheers.
While adding your app's .m files directly to your testing target solves the problem, it's redundant and unnecessary. Follow the steps outlined here by Two Bit Labs to get it working. To sum up, make sure your…
- test target's
Bundle Loader
build setting is pointing at your app's bundle. - test target's
Test Host
build setting is pointing at your app's bundle. - app target's
Symbols Hidden by Default
build setting isNO
.
精彩评论