ld: xx duplicate symbols for architecture armv7 Xcode Project

蹲街弑〆低调 提交于 2019-12-10 14:14:09

问题


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

ld: xx duplicate symbols for architecture armv7 Xcode Project clang: error: linker command failed with exit code 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?


回答1:


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!




回答2:


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




回答3:


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

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)

Then go to your project/target Build Settings -> Other Linker Flags and remove the reference to the duplicate pod (In my case, 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.



来源:https://stackoverflow.com/questions/25123776/ld-xx-duplicate-symbols-for-architecture-armv7-xcode-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!