xcode 1 个用于架构 i386 的重复符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18884190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:49:09  来源:igfitidea点击:

1 duplicate symbol for architecture i386

iphoneobjective-cxcode

提问by user2768121

I am facing a critical problem here, Xcode throws strange exception while building it's "

我在这里面临一个关键问题,Xcode 在构建它时抛出奇怪的异常“

duplicate symbol _selected in: /Users/mhgaber/Library/Developer/Xcode/DerivedData/?Project-Name-aopcbghvorqhdwbyudzqsyhtekcu/Build/Intermediates/Project-Name.build/Debug-iphonesimulator/Project-Name.build/Objects-normal/i386/ClassX.o /Users/mhgaber/Library/Developer/Xcode/DerivedData/Project-Name-aopcbghvorqhdwbyudzqsyhtekcu/Build/Intermediates/Project-Name.build/Debug-iphonesimulator/Project-Name.build/Objects-normal/i386/ClassY.o ld: 1 duplicate symbol for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

重复符号_selected:/Users/mhgaber/Library/Developer/Xcode/DerivedData/?Project-Name-aopcbghvorqhdwbyudzqsyhtekcu/Build/Intermediates/Project-Name.build/Debug-iphonesimulator/Project-Name.build/Objects-normal/i386 /ClassX.o /Users/mhgaber/Library/Developer/Xcode/DerivedData/Project-Name-aopcbghvorqhdwbyudzqsyhtekcu/Build/Intermediates/Project-Name.build/Debug-iphonesimulator/Project-Name.build/Objects-normal/i386/ClassY .o ld:架构 i386 clang 的 1 个重复符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

I searched a lot but I didn't find anything help me please

我搜索了很多,但没有找到任何帮助我的东西

回答by dtrotzjr

Look at both the files for ClassXand ClassY- What targets are they included in? Basically the _selectedmethod is duplicated in both of them. I am going to guess this is a plain C method that happens to be named the same in both files. Try renaming _selectedin one of the files.

查看文件ClassXClassY- 它们包含在哪些目标中?基本上,该_selected方法在两者中都是重复的。我猜这是一个普通的 C 方法,恰好在两个文件中命名相同。尝试_selected在其中一个文件中重命名。

回答by devios1

In my case, I was declaring a constin a header file, which worked fine when building and running on the device (iPhone 5), however when attempting to simulate a 4S, all of a sudden I had some 300 "duplicate symbols".

就我而言,我const在头文件中声明了a,它在设备(iPhone 5)上构建和运行时运行良好,但是在尝试模拟 4S 时,突然间我有大约 300 个“重复符号”。

It turns out I needed to also mark the constas staticand the issue went away. Presumably it was trying to redefine the constant every time the header was referenced. The compiler isn't smart enough to just make constants static? Didn't think that would be necessary, but I guess it is.

事实证明,我还需要将其标记conststatic,问题就消失了。大概每次引用标题时它都试图重新定义常量。编译器不够聪明,只能使常量静态?不认为这是必要的,但我想是的。

const CGFloat kTitleAnimateDistance = 50.f;

Needed to be:

需要是:

const static CGFloat kTitleAnimateDistance = 50.f;

回答by Ali Raza

Some time you accidentally importing the .m file instead of the .h due to which this error comes. Please check and If this is not the reason, then perform the following steps

有时您不小心导入了 .m 文件而不是 .h 导致出现此错误。请检查,如果这不是原因,则执行以下步骤

1- Check Build phases in Target settings.

1- 检查目标设置中的构建阶段。

2- Go to compile source section.

2- 转到编译源部分。

3- Check if any file exists twice or once.

3- 检查任何文件是否存在两次或一次。

4- If file exist twice delete one.

4-如果文件存在两次删除一个。

5- Build again.

5-再次构建。

回答by static0886

I was having the same problem and @dtrotzjr 's answer gave me a hint as to what could be causing it.

我遇到了同样的问题,@dtrotzjr 的回答给了我一个可能导致它的提示。

In my case I had a plain C voidfunction in my framework (which xcode was complaining about as a duplicate symbol) and i needed to declare it as static void

就我而言void,我的框架中有一个普通的 C函数(xcode 抱怨它是重复符号),我需要将它声明为 static void

回答by Patrick Walter

I had the same issue. I was including a .h file with a number of const strings, methods and a struct. When I changed them all to static except the only mutable variable I wanted, it compiled just fine.

我遇到过同样的问题。我包含了一个 .h 文件,其中包含许多 const 字符串、方法和一个结构。当我将它们全部更改为静态时,除了我想要的唯一可变变量外,它编译得很好。