未定义的符号:“_ OBJC_CLASS_ $ error

时间:2011-08-05 17:52:54

标签: objective-c ios xcode linker

我一直在查看有关此错误的无数帖子:

Undefined symbols:
"_OBJC_CLASS_$_BoxView", referenced from:
  objc-class-ref-to-BoxView in ViewMovingViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

BoxViewUIView的子类,并且已包含UIKit框架。已在ViewController中导入BoxView.h

ViewController包含以下代码:

-(void) addBoxViewAtLocation:(CGPoint)point {
    CGRect rect;  
    rect.origin.x = point.x;  
    rect.origin.y = point.y;  
    rect.size.width = 80;  
    rect.size.width = 40;  
    BoxView *newView = [[BoxView alloc] initWithFrame:rect];  
    newView.backgroundColor = [UIColor yellowColor];  
    [mainView addSubview:newView];  
}  

BoxView包含此代码:

- (id)initWithFrame:(CGRect)frame {     
    self = [super initWithFrame:frame];  
    if (self) {  
        // no further initialization  
    }  
    return self; 
}  

这是导致错误的行,来自上面的代码:

BoxView *newView = [[BoxView alloc] initWithFrame:rect];

当我在该行中将BoxView更改为UIView时,错误就会消失。有谁知道我需要在这里改变什么?我已经浏览过很多关于此的帖子,但是大多数答案都说它与链接有关,但我尝试勾选并取消某些方框并没有成功。我想知道错误是否在我的代码中?任何建议将不胜感激!

3 个答案:

答案 0 :(得分:42)

通常,当BoxView的代码未正确编译到目标中时会发生这种情况。

identity editor screenshot

您需要确保您正在构建的目标已为您的BoxView.m实施文件检查了相应的框。你的问题表明你已经尝试过这个,但是为了清晰起见,这里是一个截图(来自Xcode 4)。

'清洁和建造'也不会伤害。

答案 1 :(得分:1)

我只想补充一点,Ben Mosher的回答是完全正确的。但是还有另一种方法可以在目标设置中包含要构建的文件。

enter image description here

答案 2 :(得分:0)

已添加场景

如果您的项目具有模块依赖性(框架),请在构建主项目之前对其进行重建。