I have an iOS app on Xcode 4.6 and when I recently tried to build and run in the iPhone 6.1 simulator I got a "Mach-O Linker Error." It continued to say:
ld: 17 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does anyone know how to solve this?
Thanks so much!
Just go to "Build Phases" -> "Compile Sources" and look for duplicate of classes.
Check if you have "*.m" files in your #import
! It appears that was my mistake...
In my example, I declared
extern NSString const *keyString
in two different files. I renamed one of them and it solved my problem.
In my case it was constants.
NSString *const cellID = @"cellID";
This line was written in two .m files. After appending static
keyword at the start the problem was resolved.
This issue can be recreated in a new project too. You would think that defining constants in the different .m files won't have any effect as they are private. But I don't know how the compiler is handling stuffs behind the scene. On top of that when you tap the issue from issue navigator it doesn't open up a page in the editor like it does for any other issue. Really frustrating.
I am not sure I can give you a solution but I will share an answer since the same happened to me on xCode 4.6 as well. I added a C class header and implementation file and included them in main. I then decided to delete that new C Class header and implementation. When I ended up adding a new c class/header again with the same name and function calls, I ended up with your error.
Frankly, this might be a bug. The only and fastest way I fixed it was to start a new project and pull all the classes in.
Make sure you don't have non-instant methods with the same name in multiple classes (So for example if I have two viewcontrollers that are pretty similar so to move quickly I copy and paste the code from one viewcontroller to the second and they both have methods called the same thing like: NSMutableString *filteredStringFromStringWithFilter(NSString *string, NSString *filter)) then the app gets confused which of those methods to use since they are both available, RENAME IT on the second class and change any calls to that method on that class and you've removed the confusion. Don't we all want things to be more clear!
If you want to change a value both in tow different class. Do remember to mark with static keywords.
or the clang will throw such error below without any value interpretation。
Apple Mach-O Linker Error
clang: error: linker command failed with exit code 1
When you refactor a class func you will also sometimes get this error. Just go to Product-> Clean and rebuild.
Build Phases" -> "Compile Sources" click the button "Validate Settings"
it's will fix your project