为了自学 Objective C 和 Cocoa,我想写一个 diff 工具。我正在使用Cedar 测试框架,但我一辈子都无法构建我的测试包。
XCode 不会向我显示任何警告,直到我点击“运行测试”,当链接器将其玩具扔出婴儿车时。我得到的确切错误是:
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)
这是我的项目的文件夹结构:
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
这是我在 Cedar wiki 上的示例中的第LowestCommonSubsequenceTests.mm
一个测试:
#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
这里是LowestCommonSubsequence.h
:
#import <Foundation/Foundation.h>
@interface LowestCommonSubsequence : NSObject
+ (NSArray *)ofLeftArray:(NSArray *)left andRightArray:(NSArray *)right;
@end
这是LowestCommonSubsequence.m
:
#import "LowestCommonSubsequence.h"
@implementation LowestCommonSubsequence
+ (NSArray *)ofLeftArray:(NSArray *)left andRightArray:(NSArray *)right
{
return @[];
}
@end
我的#import
陈述有误吗?文件夹结构不正确?我是否错误地设置了构建目标?
我在 Cedar wiki 上发现了我的问题,它建议在调试模式下运行,但据我所知,一切都已设置为使用默认设置在调试模式下运行。
抱歉,如果这是一个愚蠢的问题。这实际上是我编写的第一个 Objective C 代码。