Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined symbols: "_OBJC_CLASS_$ error

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.

The ViewController contains this code:

-(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:

- (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!

like image 480
cms Avatar asked Aug 05 '11 17:08

cms


3 Answers

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

identity editor screenshot

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.

A 'Clean and Build' never hurts, either.

like image 89
Ben Mosher Avatar answered Oct 23 '22 23:10

Ben Mosher


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.

enter image description here

like image 4
Enrico Susatyo Avatar answered Oct 24 '22 00:10

Enrico Susatyo


Added Scenario

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

like image 1
microVinchi Avatar answered Oct 24 '22 00:10

microVinchi