2

I am trying to build a category for a project (my first time). If I implement the category in the model (LTUser), it works fine but, if I put it into a different file called LTUser+Additions(.h / .m), it gives me "linker command failed with exit code 1 (use -v to see invocation)" error with "6 duplicate symobols for architecture i386". I'm not even sure where I would add -v on invocation. I have included a screenshot of the error. What am I doing wrong with my category?

LTUser+Additions.h

#import "LTUser.h"

@interface LTUser (Additions)
-(void)saySomethingMore;
+(void)tellMe;

@end

LTUser+Additions.m

#import "LTUser+Additions.h"

@implementation LTUser (Additions)
-(void)saySomethingMore{
    NSLog(@"I want to say something more to you from within category");
}

+(void)tellMe
{
    NSLog(@"I want you to tell me from the category");
}

@end

enter image description here

edit #1 so just adding an empty category via: File -> New -> File -> 'select Objective C Category' -next-> Set name to Add and Category on LTUser

It makes the .h / .m files but if I compile this, it gives me the same error. This is making me think that adding / deleting category files has mucked up the project but still not sure.

timpone
  • 19,235
  • 36
  • 121
  • 211

2 Answers2

2

That strongly looks as if you #import a .m-file instead of the .h-file somewhere.

The same error would also occur if you put the implementation into the .h file (which you should never do), and import the .h file from more than one place.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • thx Martin, I feel foolish; I had my .h / .m files in one file (.h) since I was just mockuping up an object; this has worked fine before but I guess I had never had a category with everything in just the .h. The issue is now resolved. I had seen the answer at bottom re .h file here http://stackoverflow.com/questions/12279622/duplicate-symbols-for-architecture-i386-clang but didn't put it together. Uggh... thx for your help. – timpone Nov 26 '13 at 19:50
0

So this app was originally to just mock something up and I did a shortcut that I've done several times before but not had an issue. Rather than a .h / .m file, I put both the header and the implementation in the .h file. This worked ok when just rendering a simple object but when I added a category, it cause the above blow-up. It should probably be mentioned in the docs that, when adding a category, it MUST exist with the .h / .m file structure.

timpone
  • 19,235
  • 36
  • 121
  • 211
  • Your issue would occur as soon as you import that header+implementation file more than once. It really has nothing to do with categories. Your category just happened to be the second time you imported `LTUser.h`. – Jonathan Arbogast Nov 26 '13 at 19:50
  • 1
    You should never put the implementation into the .h file. That gives duplicate symbols as soon as the .h file is included from more than one place, independent of categories. The same problem arises if you include the .m file, which lead to my above conjecture. – Martin R Nov 26 '13 at 19:50
  • yes, lesson learned; thx again for your help. If no category, it wasn't giving me the duplicate symbol errors. – timpone Nov 26 '13 at 19:54
  • @MartinR - if you want, just add the to your answer the error I did above and I'll just accept your answer so you'll get some points – timpone Nov 26 '13 at 19:59