-->

Mach-O Linker Error on Xcode 4.6

2019-02-02 01:05发布

问题:

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!

回答1:

Just go to "Build Phases" -> "Compile Sources" and look for duplicate of classes.



回答2:

Check if you have "*.m" files in your #import ! It appears that was my mistake...



回答3:

In my example, I declared

extern NSString const *keyString

in two different files. I renamed one of them and it solved my problem.



回答4:

  1. Quit Xcode
  2. Restart the System
  3. Select Xcode -> Preferences -> Locations
  4. In Locations, you will see 'Derived Data'. Click on the arrow icon right next to the path.
  5. This will open a folder containing 'Derived Data', delete it.
  6. Clean the Product and Run

    if still not works then

    Build Settings > Enable Bitcode > No



回答5:

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.



回答6:

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.



回答7:

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!



回答8:

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



回答9:

When you refactor a class func you will also sometimes get this error. Just go to Product-> Clean and rebuild.



回答10:

Build Phases" -> "Compile Sources" click the button "Validate Settings"

it's will fix your project