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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:59:16  来源:igfitidea点击:

Undefined symbols: "_OBJC_CLASS_$ error

objective-ciosxcodelinker

提问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

BoxViewis a subclass of UIView, and the UIKitframework has been included. BoxView.hhas 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 BoxViewcontains 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 BoxViewto UIViewin 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!

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

回答by Ben Mosher

In general, this will occur when the code for BoxViewis not being compiled into your target correctly.

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

identity editor screenshot

身份编辑器截图

You need to ensure that the target you're building has its corresponding box checked for your BoxView.mimplementation 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 的回答是完全正确的。但是还有另一种方法可以将要构建的文件包含在目标设置中。

enter image description here

在此处输入图片说明

回答by microVinchi

Added Scenario

添加场景

If your project has module dependencies(framework), rebuild them before building your main project.

如果您的项目具有模块依赖项(框架),请在构建主项目之前重建它们。