ios Objective-C 构建中的重复符号错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2264455/
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
Duplicate Symbol Error in Objective-C build?
提问by fabian
I got this error when I press build+debug:
当我按 build+debug 时出现此错误:
ld: duplicate symbol .objc_class_name_BlogTableItemCell in /Users/fabian/Development/Workspaces/iphone_experiments/xcode_build_output/MausLog.build/Debug-iphonesimulator/MausLog.build/Objects-normal/i386/BlogTableItemCell-3733583914888A7B.o and /Users/fabian/Development/Workspaces/iphone_experiments/xcode_build_output/MausLog.build/Debug-iphonesimulator/MausLog.build/Objects-normal/i386/BlogTableItemCell-3733583914888A7B.o
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
回答by
You could also get this error if you mistakenly let Xcode's auto-complete for #import statements specify the '.m" file for the 'duplicate' class instead of the '.h'.
如果您错误地让 Xcode 的 #import 语句的自动完成功能为 'duplicate' 类指定了 '.m' 文件而不是 '.h',您也可能会收到此错误。
回答by Massimo Cafaro
It seems that you are compiling the same BlogTableItemCell class two times in different places of your code. This may happen in the following cases.
您似乎在代码的不同位置两次编译相同的 BlogTableItemCell 类。在以下情况下可能会发生这种情况。
You have put the same class implementation into two different files;
You actually have just one implementation of this class, however you are also linking in your project a framework or library containing a class whose name is exactly the same of yours.
您已将相同的类实现放入两个不同的文件中;
您实际上只有这个类的一个实现,但是您还在项目中链接了一个框架或库,其中包含一个名称与您的名称完全相同的类。
Try finding in the whole project your class and make sure only one copy is available within your project.
尝试在整个项目中查找您的班级,并确保您的项目中只有一个副本可用。
回答by NeilNie
For me, changing 'No Common Blocks' from Yes to No ( under Targets->Build Settings->Apple LLVM - Code Generation )
对我来说,将“No Common Blocks”从 Yes 更改为 No(在 Targets->Build Settings->Apple LLVM - Code Generation 下)
回答by jsaven
I had a similar problem due to poor defining of consts. I had defined a const in my header:
由于 const 的定义不佳,我遇到了类似的问题。我在我的标题中定义了一个常量:
int const kCropLocationTop = 1;
This was presumably imported multiple times. To fix i changed the header def as follows:
这可能是多次进口的。为了解决这个问题,我改变了标题 def 如下:
extern int const kCropLocationTop;
and moved the assigning of the const to the .m file:
并将 const 的分配移至 .m 文件:
int const kCropLocationTop = 1;
Hope that helps anyone who's as ignorant of simple objective c concepts as I am!
希望能帮助像我一样对简单的客观 c 概念一无所知的人!
回答by Pratik
By mistake the source file was included twice in the Project -> Build Phase -> Compile Sources. Removing one of them solved the problem.
错误地将源文件包含在 Project -> Build Phase -> Compile Sources 中两次。删除其中之一解决了问题。
回答by bradgonesurfing
iPhone: Duplicate Symbol Error?by user576924
iPhone:重复符号错误?来自用户576924
answered it correctly for me. However to find the offending gremlin this ZSH snippet.
为我正确回答。但是要找到这个 ZSH 代码段中的有问题的小鬼。
grep "import.*\.m" **/*.[hm]
Will immediately tell you where your error is.
会立即告诉你你的错误在哪里。
回答by JohnVanDijk
The most common reason for this error is importing an xyz.m file instead of the xyz.h file.
Check if your imports contain something like
#import "----.m"
此错误的最常见原因是导入 xyz.m 文件而不是 xyz.h 文件。检查您的导入是否包含类似
#import "----.m"
回答by ChargedNeuron
Just to add; Using Xcode to generate subclassed managed objects (Core Data) can sometimes duplicate the generated files. For me the fix was to delete the generated files and re-generate them.
只是补充; 使用 Xcode 生成子类托管对象(Core Data)有时会复制生成的文件。对我来说,修复是删除生成的文件并重新生成它们。
回答by DBD
I just ran into this problem myself. For the list, here's another possibility:
我自己刚刚遇到了这个问题。对于列表,这是另一种可能性:
Duplicated linking line in the project file.
项目文件中的链接行重复。
I caused this merging conflicts on a SVN update, when I accidentally duplicated a line.
当我不小心复制了一行时,我在 SVN 更新中导致了这种合并冲突。
回答by Bruce Cichowlas
It happened to me, too. In my case, one (just one) of my core data automatically generated classes was inserted twice. I spotted the duplication by looking at Build Phases...Compile Sources. Simply deleting one of the occurrences solved the problem.
它也发生在我身上。就我而言,我的一个(仅一个)核心数据自动生成的类被插入了两次。我通过查看 Build Phases...Compile Sources 发现了重复。只需删除其中一个即可解决问题。