ld:架构 armv7 Xcode 项目的 xx 重复符号

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

ld: xx duplicate symbols for architecture armv7 Xcode Project

iosxcodeldduplicate-symbol

提问by Meeko

Hi everybody I have a Xcode project that gives me this error every time I try to build the project:

大家好,我有一个 Xcode 项目,每次尝试构建项目时都会出现此错误:

ld: xx duplicate symbols for architecture armv7 Xcode Project clang: error: linker command failed with exit code 1...

ld:架构 armv7 Xcode 项目的 xx 重复符号叮当声:错误:链接器命令失败,退出代码为 1...

I have googled around and most solutions say to get rid of duplicate files in the build phase->Compile Resources section of the project or to change the import .m to .h in some files. Problem is the list of compiled resources isn't even sorted and I do not even know which files to fix since there are a lot of files in my project. Any advice on how on how to clean this up?

我已经四处搜索,大多数解决方案都说要在项目的构建阶段-> 编译资源部分中删除重复文件,或者将某些文件中的导入 .m 更改为 .h。问题是编译资源的列表甚至没有排序,我什至不知道要修复哪些文件,因为我的项目中有很多文件。关于如何清理它的任何建议?

回答by Adam Evans

I have had this error sometimes, and the issue is always this. I have a static variable in the .m of one class, and another static variable with the same name in another .m. Apparently the compiler does not like it when there are two static variables with the same name, whether in different files or not. So check for any duplicate static variable names or #define macros. Also, it might not be duplicate files or files imported twice. If two different files are imported, but each has a variable or macro with the same name, there will be an error because the compiler can't figure out which one to use. The conflicting variables should be in the files mentioned in the error. Hope this helps!

我有时会遇到这个错误,问题总是这个。我在一个类的 .m 中有一个静态变量,在另一个 .m 中有另一个同名的静态变量。显然编译器不喜欢有两个同名的静态变量,无论是否在不同的文件中。因此,请检查是否有任何重复的静态变量名称或 #define 宏。此外,它可能不是重复的文件或两次导入的文件。如果导入了两个不同的文件,但每个文件都有一个同名的变量或宏,就会出现错误,因为编译器无法确定使用哪个。冲突的变量应该在错误中提到的文件中。希望这可以帮助!

回答by Geet

There are certain Files in your project which may have been imported twice, try to analyse the error log, it must be referring the file where somewhere you must be getting an error as "YourViewCOntroller.O" its finding the double files,search for "YourViewCOntroller" in your project navigator, You need to remove these files from your Xcode project and then build again

您的项目中有某些文件可能已导入两次,请尝试分析错误日志,它必须将您必须在某处收到错误的文件称为“YourViewCONtroller.O”,它找到了双重文件,搜索“您的项目导航器中的“YourViewCONtroller”,您需要从 Xcode 项目中删除这些文件,然后重新构建

回答by Jacques.S

If you are using Cocoapodslike me, you may find that the other answers are not helping, because the duplicates are generated by the pod file automatically.

如果您像我一样使用Cocoapods,您可能会发现其他答案没有帮助,因为重复项是由 pod 文件自动生成的。

What worked for me was to look at the list of duplicate symbols, for example:

对我有用的是查看重复符号列表,例如:

duplicate symbol _OBJC_METACLASS_$_AFImageCache in:

___/Build/Products/Debug-iphoneos/libPods-AFNetworking.a(UIImageView+AFNetworking.o)

___/Build/Products/Debug-iphoneos/libAFNetworking.a(UIImageView+AFNetworking.o)

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

重复符号 _OBJC_METACLASS_$_AFImageCache 在:

___/Build/Products/Debug-iphoneos/libPods-AFNetworking.a(UIImageView+AFNetworking.o)

___/Build/Products/Debug-iphoneos/libAFNetworking.a(UIImageView+AFNetworking.o)

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

Then go to your project/target Build Settings -> Other Linker Flagsand remove the reference to the duplicate pod (In my case, AFNetworking).

然后转到您的项目/目标构建设置 -> 其他链接器标志并删除对重复 pod 的引用(在我的情况下,AFNetworking)。

Clean, build again and it should work.

清洁,再次构建,它应该可以工作。

--

——

As far as I can tell, this may be happening because one of the other pods references AFNetworking, leading to a duplicate.

据我所知,这可能是因为其他 pod 之一引用了 AFNetworking,导致重复。