I ran into a situation where I had the following two implementations located in separate files:
ClassA.m
@implementation ClassA
int _x = 0;
@end
ClassB.m
@implementation ClassB
int _x = 0;
@end
When I compiled, the linker would state:
objective c duplicate symbol __x….
My solution was to mark both variables as static.
Is it then true that all member variables of Classes are just munged into the symbol table without their implementing Classname prepended (unless you mark them as static)? I’d find that hard to believe, otherwise I’d think using static would be the rule, not the exception…
You’ve not declared instance variables of the class there; you’ve declared global variables hence why the linker tells you that there’s 2 symbols called
_x.You probably wanted to put them in your
@interfaceforClassAandClassB.