ios 未定义的符号:“_OBJC_CLASS_$ 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6960543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undefined symbols: "_OBJC_CLASS_$ error
提问by cms
I've been looking through countless posts about this error:
我一直在查看无数关于此错误的帖子:
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
BoxView
is a subclass of UIView
, and the UIKit
framework has been included. BoxView.h
has been imported in the ViewController.
BoxView
是 的子类UIView
,并且UIKit
已经包含了框架。BoxView.h
已经导入到 ViewController 中。
The ViewController contains this code:
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];
}
And BoxView
contains this code:
并BoxView
包含此代码:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// no further initialization
}
return self;
}
This is the line that's causing the error, from the code above:
这是导致错误的行,来自上面的代码:
BoxView *newView = [[BoxView alloc] initWithFrame:rect];
When I change BoxView
to UIView
in that line, the error goes away. Does anyone know what I need to change here? I have looked through many posts about this, but most answers say it's link related, but I've tried ticking and unticking certain boxes with no success. I'm wondering if the error is in my code? Any suggestions would be appreciated!
当我改变BoxView
到UIView
该行,错误消失。有谁知道我需要在这里改变什么?我浏览了很多关于此的帖子,但大多数答案都说它与链接相关,但我尝试勾选和取消勾选某些框但没有成功。我想知道错误是否在我的代码中?任何建议,将不胜感激!
回答by Ben Mosher
In general, this will occur when the code for BoxView
is not being compiled into your target correctly.
通常,当代码BoxView
没有正确编译到您的目标时会发生这种情况。
You need to ensure that the target you're building has its corresponding box checked for your BoxView.m
implementation file. Your question suggests that you've tried this, but here's a screenshot (from Xcode 4) just for clarity's sake.
您需要确保您正在构建的目标为您的BoxView.m
实现文件选中了相应的框。您的问题表明您已经尝试过这个,但为了清楚起见,这里有一个屏幕截图(来自 Xcode 4)。
A 'Clean and Build' never hurts, either.
“清洁和构建”也永远不会受到伤害。
回答by Enrico Susatyo
I just want to add that Ben Mosher's answer is totally right. But there's another way to include the files to build in the Target settings.
我只想补充一点,Ben Mosher 的回答是完全正确的。但是还有另一种方法可以将要构建的文件包含在目标设置中。
回答by microVinchi
Added Scenario
添加场景
If your project has module dependencies(framework), rebuild them before building your main project.
如果您的项目具有模块依赖项(框架),请在构建主项目之前重建它们。