gpt4 book ai didi

iphone - 重复符号 _calculate_string 错误消息 iPhone

转载 作者:行者123 更新时间:2023-11-28 23:08:15 26 4
gpt4 key购买 nike

这是我尝试构建测试时得到的错误代码,我如何找到此错误的原因。我在 xcode 中复制了 2 个文件,并对副本进行了细微的更改以制作第二个屏幕。

ld: duplicate symbol _calculate_string in /Users/Lucky3kj/Library/Developer/Xcode   /DerivedData/MiniCalculator-ebxkovztnlrphaahncircdyuwjgc/Build/Intermediates/MiniCalculator.build/Debug-iphoneos/PipeFitter.build/Objects-normal/armv7/RollingOffsetLeftViewController.o and /Users/Lucky3kj/Library/Developer/Xcode/DerivedData/MiniCalculator-ebxkovztnlrphaahncircdyuwjgc/Build/Intermediates/MiniCalculator.build/Debug-iphoneos/PipeFitter.build/Objects-normal/armv7/RollingOffsetAnyAngleViewController.o for architecture armv7
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang failed with exit code 1

最佳答案

基本上,这是一个源于 C 的错误。

如果在一个 .c 文件中有以下内容:

void myFunction(int myArg)
{
printf("%i", myArg);
}

在另一个文件中我有这个函数:

void myFunction(int myArg)
{
printf("MyArg is: %i", myArg);
}

当编译器链接你的项目,你调用

myFunction(10);

编译器不知道调用你的方法的哪个版本,所以解决方案是以下之一:

1) 定义一次方法,并且只包含函数的原型(prototype)。示例:

// instead of implementing myFunction here, we do this:
void myFunction(int myArg);
// and implement myFunction in another file.

-(void) viewDidLoad {
myFunction(10);
}

2) 两次定义该方法,但为其添加静态限定符,它告诉链接器这是唯一可以使用该函数的文件。

// FileOne.c

static void myFunction(int myArg)
{
printf("myArg is: %i", myArg);
}

// FileTwo.c

static void myFunction(int myArg)
{
printf("%i", myArg);
}

老实说,为了简单起见,我建议只使用静态限定符,但这只是我在这些问题上的偏好。

关于iphone - 重复符号 _calculate_string 错误消息 iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8870299/

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