xcode 4.6.1 和 LLVM 4.2:ld:架构 armv7 的 2 个重复符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16005341/
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:12:52  来源:igfitidea点击:

xcode 4.6.1 and LLVM 4.2: ld: 2 duplicate symbols for architecture armv7

objective-cxcodeframeworkslinkerlinker-errors

提问by ?lex

My first attempt at building a company iOS library/framework was this week, by following the steps found at this blog post here.

我第一次尝试构建公司的 iOS 库/框架是在本周,按照这篇博文中的步骤在这里

For reasons beyond this question, I can only link when building for a Device and not for simulator.

出于这个问题之外的原因,我只能在为设备而不是模拟器构建时进行链接。

However, now I am getting a very bizarre error:

但是,现在我遇到了一个非常奇怪的错误:

ld: 2 duplicate symbols for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

ld:架构 armv7 clang 的 2 个重复符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

The lines in question suggest:

有问题的行表明:

duplicate symbol _OBJC_CLASS_$_iContactsGridCell in: /Users/*/Desktop/Projects/contactservice/branch/ContactServicesClient/DerivedData/iContacts/Build/Intermediates/iContacts.build/Debug-iphoneos/iContacts-5.1.build/Objects-normal/armv7/iContactsGridCell.o /Applications/Xcode.app/Contents/Developer/Library/Frameworks/athium-iOS.framework/athium-iOS duplicate symbol _OBJC_METACLASS_$_iContactsGridCell in: /Users/*/Desktop/Projects/contactservice/branch/ContactServicesClient/DerivedData/iContacts/Build/Intermediates/iContacts.build/Debug-iphoneos/iContacts-5.1.build/Objects-normal/armv7/iContactsGridCell.o /Applications/Xcode.app/Contents/Developer/Library/Frameworks/athium-iOS.framework/athium-iOS

重复符号 _OBJC_CLASS_$_iContactsGridCell 在:/Users/ */Desktop/Projects/contactservice/branch/ContactServicesClient/DerivedData/iContacts/Build/Intermediates/iContacts.build/Debug-iphoneos/iContacts-5.1.build/Objects-normal/armv7 iContactsGridCell.o /Applications/Xcode.app/Contents/Developer/Library/Frameworks/athium-iOS.framework/athium-iOS 重复符号 _OBJC_METACLASS_$_iContactsGridCell 在:/Users/ */Desktop/Projects/contactservice/branch/ContactServicesClient/DerivedData /iContacts/Build/Intermediates/iContacts.build/Debug-iphoneos/iContacts-5.1.build/Objects-normal/armv7/iContactsGridCell.o /Applications/Xcode.app/Contents/Developer/Library/Frameworks/athium-iOS.framework /athium-iOS

Obviously the Class in question is iContactsGridCell.h

显然有问题的类是 iContactsGridCell.h

The class itself inherits from Cell.h

类本身继承自 Cell.h

@interface iContactsGridCell : Cell

The class Cell.h is part of the framework, if I do not import the correct file, then as expected I get a semantic error: Cannot find interface declaration for Celletc etc.

类 Cell.h 是框架的一部分,如果我没有导入正确的文件,那么正如预期的那样,我会收到一个语义错误:找不到 Cell等的接口声明等。

However, when I do import it, I get the following duplicate error. This file is not included anywhere else in the project, apart from iContactsGridCell.h!

但是,当我导入它时,出现以下重复错误。除了iContactsGridCell.h之外,该文件不包含在项目中的任何其他地方!

The file Cell.hin turn, is just a class found under the framework:

反过来,文件Cell.h只是在框架下找到的一个类:

@interface Cell : NSObject

@property (strong,nonatomic) UIView *view;
@property CGRect rect;
@property int UID;
@property BOOL highlighted;
@property UIColor *b_colr;

- (id) initWithRect:(CGRect)frame;
- (BOOL) hasCoordinates:(CGPoint)coord;
- (void) ripple;
- (void) cubefy;
- (void) flipfy;
- (void) rotate;
- (void) setBg:(UIColor *)bg withAlpha:(CGFloat)alpha;
- (void) highlight;
- (void) unhighlight;
- (void) updateWithRect:(CGRect)rect;

@end
  1. Why on earth am I getting the duplicate error?
  2. What could be causing this?
  3. How could it get fixed?
  4. How can I get more info more verbose output of wherethe duplicates are found?
  1. 为什么我会收到重复的错误?
  2. 什么可能导致这种情况?
  3. 怎么可能修好?
  4. 我怎样才能获得更多信息,更详细的输出在哪里找到重复项?

PS: I have followed the intructions found at the blog to the letter. Yet I cannot link for simulator (getting a wrong architecture error) so my guess that maybe something is broken in the framework and not the project itself. Could this be the reason for the duplicate errors?

PS:我已经按照博客上的说明进行了操作。然而,我无法链接模拟器(出现错误的架构错误),所以我猜测可能是框架中的某些东西损坏了,而不是项目本身。这可能是重复错误的原因吗?

回答by ManOx

There are several places where this error could be arising. I would do the following to start searching for the problem:

有几个地方可能会出现此错误。我将执行以下操作以开始搜索问题:

  1. Search the project folder with finder and see if anywhere else the file "iContactsGridCell.h" exists. Or if any two files exist somewhere.
  2. Make sure that you don't have two Objects that are of Class iContactsGridCell that share the same name for example:
  1. 使用 finder 搜索项目文件夹并查看文件“iContactsGridCell.h”是否存在其他任何地方。或者,如果某处存在任何两个文件。
  2. 确保您没有两个共享相同名称的 iContactsGridCell 类对象,例如:

iContactsGridCell *myObj; iContactsGridCell *myObj;

iContactsGridCell *myObj; iContactsGridCell *myObj;

  1. Make sure your not doing anything like this: #import "iContactsGridCell .m"

  2. Or like this: #import "iContactsGridCell.h" #import "iContactsGridCell.h"

  3. Make sure your not re-declaring a class (including ones that Apple has provided in their frameworks)
  1. 确保你没有做这样的事情:#import "iContactsGridCell .m"

  2. 或者像这样:#import "iContactsGridCell.h" #import "iContactsGridCell.h"

  3. 确保您没有重新声明类(包括 Apple 在其框架中提供的类)

Main Point:That's all I can think of off the top of my head. But the thing to remember is that somewhere in your project resides two objects, class declarations etc. That are the same. And the compiler is complaining because of it.

要点:我能想到的就这些。但要记住的是,项目中的某个地方驻留了两个对象、类声明等。它们是相同的。编译器因此而抱怨。

Why the Compiler would complain (more info):While this information is really "unnecessary" it's good practice as a programmer to understand what's going on under the hood and will often help debug, so here's a little info on compilers:

为什么编译器会抱怨(更多信息):虽然这些信息确实是“不必要的”,但作为程序员了解幕后发生的事情并且通常有助于调试是一个很好的做法,所以这里有一些关于编译器的信息:

Remember that a Compiler (while much more complex) is a program just like the ones that you create using it. One of the steps in most (if not all) compilers go through at one point or another reading code is creating "Symbols or Keys" for each variable, class, struct ect. So, at some point the compiler reached a line of code that "repeats / duplicates" somewhere else. So the "Key/Symbol" creation process done routine by the compiler fails.

请记住,编译器(虽然要复杂得多)是一个程序,就像您使用它创建的程序一样。大多数(如果不是全部)编译器在一个点或另一个阅读代码中执行的步骤之一是为每个变量、类、结构等创建“符号或键”。因此,在某些时候,编译器会在其他地方“重复/重复”一行代码。所以编译器完成的“键/符号”创建过程失败了。