【问题标题】:Linker error with Cedar testsCedar 测试的链接器错误
【发布时间】:2013-08-18 20:33:31
【问题描述】:

为了自学 Objective C 和 Cocoa,我想写一个 diff 工具。我正在使用the Cedar testing framework,但我一辈子都无法构建我的测试包。

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

这是我在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 代码。

【问题讨论】:

    标签: objective-c linker linker-errors cedar-bdd


    【解决方案1】:

    您使用的是规范套件吗?

    如果是这样,您必须将包含 LongestCommonSubsequence 实现的文件添加到规范套件目标。

    【讨论】:

    • 我使用的是捆绑包,而不是套件。
    【解决方案2】:

    我通过更改测试包的构建设置解决了这个问题:

    捆绑加载器:$(BUILT_PRODUCTS_DIR)/&lt;App Name&gt;.app/Contents/MacOS/&lt;App Name&gt; 测试主机:$(BUNDLE_LOADER)

    【讨论】:

      猜你喜欢
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2014-08-12
      相关资源
      最近更新 更多