1

While attempting to compile and run my project, I ran into the error above. Here is a more detailed look:

duplicate symbol _timeTick in:
/Users/zstephen/Library/Developer/Xcode/DerivedData/MyStore_2-ejjgywkgxdulkogcohzbzojgqpzp/Build/Intermediates/MyStore 2.build/Debug-iphonesimulator/MyStore.build/Objects-normal/i386/TimeController.o
/Users/zstephen/Library/Developer/Xcode/DerivedData/MyStore_2-ejjgywkgxdulkogcohzbzojgqpzp/Build/Intermediates/MyStore 2.build/Debug-iphonesimulator/MyStore.build/Objects-normal/i386/DeviceDetailViewController.o
ld: 1 duplicate symbol for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)

How do I fix this issue? Thanks in advance!

UPDATE: Here is the 3 files timeTick is used:

.h:

#import <UIKit/UIKit.h>

int timeTick = 0;

@interface TimeController : UIViewController{
IBOutlet UILabel *labelTime;
}
- (IBAction)startTimer:(id)sender;


@end

.m:

@implementation TimeController


NSTimer *timer;   

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    labelTime.text = @"0";
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

    - (IBAction)startTimer:(id)sender {
    [timer invalidate];
    timer= [NSTimer scheduledTimerWithTimeInterval:60.0 target:(self) selector:             (@selector(tick)) userInfo:(nil) repeats:(YES)];
}

-(void)tick{
    timeTick++;
    NSString *timeString = [[NSString alloc] initWithFormat:@"%d", timeTick];
    labelTime.text = timeString;



}


@end

Finally, there is a separate file that saves and loads timeTick into Core Data.

.m:

NSNumber *timetickNumber = [NSNumber numberWithInt:timeTick];
[newDevice setValue:timetickNumber forKey:@"name"];
4
  • The error says that you have the same symbol _timeTick declared in both methods as a global. Don't do that. Show the code of the declarations of _timeTick in easm file. Commented Oct 28, 2013 at 3:22
  • @Zaph I have deleted all references to _timeTick. The error still occurs. I am using a int called timeTick. Is this affecting? Commented Oct 28, 2013 at 3:31
  • Possibly. Post the code where timeTick is used and we can give you more information. Commented Oct 28, 2013 at 3:32
  • @user1118321 I have uploaded my timeTick code. Does this cause the error? Commented Oct 28, 2013 at 3:49

1 Answer 1

1

What's happening is that every file that #imports the .h file now has it's own variable named timeTick. What you need to do is make it an external in the header, then define it in the .m file. So you're .h should look like this:

extern int timeTick;

Then your .m should have this at the top of the file:

int timeTick = 0;

Then any file which needs access to it would #import ".h" and see the definition. Since it's external they won't create their own timeTick but will look for one at link time, which they'll find in the .m file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.