iOS programming - Duplicate symbol _OBJC_IVAR

Viewed 19615

operator class:

#import <Foundation/Foundation.h>


@interface operator : NSObject {

int number;
}

@property int number;

@end

@implementation operator

- (id)init{
    self = [super init];
    if (self) {
    [self setNumber:0];
    }
    return self;
}

@synthesize number;
@end

main.m:

#import <UIKit/UIKit.h>
#import "operator.m"

int main(int argc, char *argv[]) {

id operator1 = [[operator alloc] init];
id operator2 = [[operator alloc] init];

[operator1 setNumber:10];
[operator2 setNumber:20];

int answer = [operator1 number] + [operator2 number];

printf("The answer is %d",answer);



NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}

I get an error -> ld: duplicate symbol _OBJC_IVAR_$_operator.number in /Volumes/Home/Desktop/testing/build/testing.build/Debug-iphonesimulator/testing.build/Objects-normal/i386/operator.o and /Volumes/Home/Desktop/testing/build/testing.build/Debug-iphonesimulator/testing.build/Objects-normal/i386/main.o

This is my very first time I program in ObjC. Am I doing something wrong?

I tried the "Clean all targets" fix that I found on google but did not help.

5 Answers

In my case, i found a double declaration on a .m file in my Build Phases --> Compile Sources. Deleting the duplicate solved the problem for me. Hope this helps.

Related