To teach myself Objective C and Cocoa, I want to write a diff tool. I'm using the Cedar testing framework, and I can't for the life of me get my test bundle to build.
XCode doesn't present me with any warnings until I hit 'run tests', when the linker throws its toys out of the pram. The exact error I'm getting is:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_LongestCommonSubsequence", referenced from:
objc-class-ref in LowestCommonSubsequenceTests.o
(maybe you meant: _OBJC_CLASS_$_LowestCommonSubsequenceTests)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here's the folder structure of my project:
Project: Diff
Diff
AppDelegate.h
AppDelegate.m
MainMenu.xib
LowestCommonSubsequence.h
LowestCommonSubsequence.m
Supporting Files
DiffTests
LowestCommonSubsequenceTests.mm
Rakefile
Cedar.framework
Supporting Files
Frameworks
Products
Here is my first test in LowestCommonSubsequenceTests.mm
, which I paraphrased from the example on the Cedar wiki:
#import "LowestCommonSubsequence.h"
using namespace Cedar::Matchers;
using namespace Cedar::Doubles;
SPEC_BEGIN(LowestCommonSubsequenceTests)
describe(@"When both input arrays are empty", ^{
it(@"should return an empty array", ^{
[LowestCommonSubsequence ofLeftArray:@[] andRightArray:@[]] should be_empty;
});
});
SPEC_END
Here is LowestCommonSubsequence.h
:
#import <Foundation/Foundation.h>
@interface LowestCommonSubsequence : NSObject
+ (NSArray *)ofLeftArray:(NSArray *)left andRightArray:(NSArray *)right;
@end
And here is LowestCommonSubsequence.m
:
#import "LowestCommonSubsequence.h"
@implementation LowestCommonSubsequence
+ (NSArray *)ofLeftArray:(NSArray *)left andRightArray:(NSArray *)right
{
return @[];
}
@end
Do I have my #import
statement wrong? Is the folder structure incorrect? Did I set up my build targets wrong?
I found my problem on the Cedar wiki, which suggested running in Debug mode, but as far as I can make out, everything is already set up to run in Debug mode with the default settings.
Apologies if this is an idiotic question. This is literally the first Objective C code I've ever written.
I fixed the issue by changing the Build Settings for the test bundle:
Bundle Loader: $(BUILT_PRODUCTS_DIR)/<App Name>.app/Contents/MacOS/<App Name>
Test Host: $(BUNDLE_LOADER)