教自己Objective C和Cocoa,我想写一个diff工具。我正在使用the Cedar testing framework,而我无法在我的生活中获得我的测试包。
XCode在我点击'run tests'之前没有给我任何警告,当链接器将玩具扔出婴儿车时。我得到的确切错误是:
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
这是我在LowestCommonSubsequenceTests.mm
中的第一次测试,我从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
以下是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
声明错了吗?文件夹结构不正确吗?我的构建目标设置错了吗?
我发现我的问题on the Cedar wiki,建议在调试模式下运行,但据我所知,所有内容都已设置为在调试模式下使用默认设置运行。
如果这是一个愚蠢的问题,请道歉。这实际上是我写过的第一个Objective C代码。
答案 0 :(得分:0)
您使用的是规格套件吗?
如果是这样,您必须将包含LongestCommonSubsequence
实现的文件添加到规范套件目标。
答案 1 :(得分:0)
我通过更改测试包的Build Settings来修复此问题:
Bundle Loader:$(BUILT_PRODUCTS_DIR)/<App Name>.app/Contents/MacOS/<App Name>
测试主持人:$(BUNDLE_LOADER)