試圖編譯和運行我的項目時,我遇到了上述錯誤。這裏是一個更詳細的研究:鏈接器命令失敗,退出代碼1錯誤
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
鐺:錯誤:連接命令,退出代碼1失敗(使用-v看到調用)
我該如何解決這個問題?提前致謝!
更新:這裏是3個文件是用來TIMETICK:
.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
最後,是保存和載入一個單獨的文件timeTick進入核心數據。
.M:
NSNumber *timetickNumber = [NSNumber numberWithInt:timeTick];
[newDevice setValue:timetickNumber forKey:@"name"];
錯誤表示您在兩種方法中都將相同的符號_timeTick聲明爲全局符號。不要這樣做。在easm文件中顯示_timeTick的聲明代碼。 – zaph
@Zaph我刪除了所有對_timeTick的引用。錯誤仍然發生。我正在使用一個名爲timeTick的int。這是否影響? – PanicDev
可能。發佈timeTick的代碼,我們可以給你更多的信息。 – user1118321