gpt4 book ai didi

xcode - 链接器命令失败,出现退出代码1错误

转载 作者:行者123 更新时间:2023-12-02 10:46:59 25 4
gpt4 key购买 nike

在尝试编译和运行我的项目时,我遇到了上面的错误。这是更详细的外观:

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查看调用)

如何解决此问题?提前致谢!

更新:这是使用timeTick的3个文件:

。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保存并加载到Core Data中。

.m:
NSNumber *timetickNumber = [NSNumber numberWithInt:timeTick];
[newDevice setValue:timetickNumber forKey:@"name"];

最佳答案

发生的事情是,现在#import成为.h文件的每个文件都具有自己的名为timeTick的变量。您需要做的是在 header 中将其设置为外部,然后在.m文件中对其进行定义。因此,您的.h应该如下所示:

extern int timeTick;

然后,您的 .m应该在文件顶部具有:
int timeTick = 0;

然后,任何需要访问它的文件都将添加 #import ".h"并查看其定义。由于它是外部的,因此他们不会创建自己的 timeTick,但会在链接时查找一个,这将在 .m文件中找到。

关于xcode - 链接器命令失败,出现退出代码1错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19626657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com