Build problem relating to import of BNRItem.h


Hello everyone,

I tried building at the end of the section “Creating and retrieving UITableViewCells” in Chapter 9 and ran into the following linker errors:

Undefined symbols for architecture i386:
"OBJC_CLASS_BNRItem", referenced from: objc-class-ref in BNRItemStore.o (maybe you meant: _OBJC_CLASS__BNRItemStore)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

After debugging I found that I can get the program to run if I change "#import “BNRItem.h” to "#import “BNRItem.m” at the top of BNRItemStore.m:

#import “BNRItemStore.h”
#import “BNRItem.m”

Does anyone know what the problem might be? Is it acceptable to import a .m file into another .m file? Should the compiler know to automatically pull in a .m file when only a .h file is specified?

Thank you very much!

Btw, for reference, here is my BNRItem.h file:

#import <Foundation/Foundation.h>

@interface BNRItem : NSObject

  • (id)randomItem;
  • (id)initWithItemName:(NSString *)name
    serialNumber:(NSString *)sNumber;

@property (nonatomic, strong) BNRItem *containedItem;
@property (nonatomic, weak) BNRItem *container;

@property (nonatomic, copy) NSString *itemName;
@property (nonatomic, copy) NSString *serialNumber;
@property (nonatomic) int valueInDollars;
@property (nonatomic, readonly, strong) NSDate *dateCreated;




I had the same problem. I removed BNRItem.h and BNRItem.m from the project and re-added them. The error went away.



Same problem here. It seems like the current XCode release has a problem importing files via “drag and drop”. I’ve seen this issue twice now. I can’t get the issue correct on my Mac even with deleting and reimporting the files when I add the files via “drag and drop”. I can solve the problem if I don’t do a “drag and drop” but instead go to “File” and click the “Add files to . . .” menu and then go find the files that way. That should make no difference at all, but it does.


Importing the .m module is not the way stylish programmers would go about fixing the problem you are experiencing. Better to find out why you are having the problem and then fix it properly :slight_smile:


Hi everyone,

I added the files back in using the “Add” menu option and it works correctly now. Thank you very much for taking the time to respond!



Thanks for the heads-up on this. I was pulling out what little hair I had left trying to figure out what I had done wrong!


This was the highest post on this topic, which is posted twice in this forum. I don’t see the answer in here so I will add it as I also had this issue. You need to have “Add to targets” checked when you import the files or you will get the error. Maybe an oversight in the book, or maybe a way for us all the practice that “linker” debugging issue we went over in a previous chapter :wink:


This happened in an earlier exercise along with this one to me. Both because of drag and drop. I will now just add files from the menu.


I’ve used dragging and dropping before but apparently with this release of Xcode it doesn’t work any more. Add files… via the menu did the trick for me as well.

Regards, Dorus


Next time you just need to select project, target, build phases and add BNRItem.m or whatever missing to Compile sources section.


Okay, I seemed to have the same linker issue, but I figured out why dragging and dropping the BNRItem files didn’t link properly. I’m using XCode 4.5.2.
First, I deleted the two BNRItem files from the project.
Next, I dragged the BNRItem files from the finder to the project, but making sure I checked the checkbox for adding to target Homepwner. This fixed the linker problem for me.


That’s right

add BNRItem.m to solve this problem.


This is what I did.
First I was like WTF, when the build failed. Then I looked at the error and could see it was a compile error relating to BNRItem.h.

So, I went to compile sources and just added the files - sorted out the issue.

However, the question still remains - why does xCode not do this automatically with the drag & drop method?