[objective-c] build failed with: ld: duplicate symbol _OBJC_CLASS_$_Algebra5FirstViewController

I am getting this error suddenly when running my app via iPhone simulator:

clang: error: linker command failed with exit code 1 (use -v to see invocation):

ld: duplicate symbol _OBJC_CLASS_$_Algebra5FirstViewController in .../Algebra5-anwcuftojtxtgkfootneeeqhwztj/Build/Intermediates/Algebra5.build/Debug-iphonesimulator/Algebra5.build/Objects-normal/i386/ExercisesViewController.o and .../Algebra5-anwcuftojtxtgkfootneeeqhwztj/Build/Intermediates/Algebra5.build/Debug-iphonesimulator/PSLE Algebra5.build/Objects-normal/i386/PSLE_Algebra5FirstViewController.o for architecture i386

What is it all about?

This question is related to objective-c ios xcode ios5.1

The answer is


I met it when import a ViewController.m in TableViewController. Try to delete '#import "ViewController.m"' if it exited. Hope this help!


I found this article that provided a solution for me. It pertains to Xcode 7 where the default for No Common Blocks is Yes rather than No in previous versions.

This is a quote from the article:

The problem seems to be that the "No common blocks" in the "Apple LLVM 6.1 - Code Generation" section in the Build settings pane is set to Yes, in the latest version of Xcode.

This caused what I will describe as circular references where a class that was included in my Compile Sources was referenced via a #import in another source file (appDelegate.m). This caused duplicate blocks for variables that were declared in the original base class.

Changing the value to No immediately enabled my app to compile and resolved my problem.


I got this same issue when working with Bolts.framework. It turns out that when Bolts gets corrupted, no amount of re-importing will fix the issue. I had to go back to the original download file and reimport it completely from scratch. This fixed it right away. It was such a weird issue that it took me forever to figure it out... hopefully this tip will spare some of you from the same frustrations :)


I was getting similar error and I got it resolved this way.

Try to set Build Active Architecture Only to NO for 'Pods' project and your app's target


once i got

18 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1

For me this was due to that i have used "const NSInteger" in my switch case.

What i did is change the const NSInteger to enum, and replace the reference with enum values.

This fixed the error for me.


I received this once by (accidentally) importing both the .h and .m files into the same class.


Simply cleaning CMD + SHIFT + K, then building CMD + B worked for me.


I got this error while implementing a subclass without the necessary framework added (MPMoviePlayerController without the MediaPlayer framework, in this example)


In my case I had a reference to a library in Other Linker Flags. Removing it got rid of the error.

enter image description here

enter image description here


It seems that for m, I dragged the files into the project and after that didn't work, clicked file "add files to project". Both were the incorrect approach. just drag it into the projects folder (in finder) that houses the other .h and .m files.


I had same problem. Got it solved!

If you have imported any files into project then check .m (main) file for same does exists in Targets (Project Name) -> Build Phases -> Compile Sources.

If file does not exists then include it using (+) Add button shown. Also, if duplicate files exists (if any) then delete it.

Now press cmd+shift+k to clean the project. New Build should not display this error.

enter image description here


Running Xcode 4.6.3 on OSX 10.7.5 was able to fix this error by changing Architectures to Native Architecture of Build Machine from $(NATIVE_ARCH_ACTUAL).


also had this problem by declaring a const * NSString in the header file (incorrectly) instead of the implementation file (correctly)


This happens either, some files are missing in the "Compile Sources" section, or duplicate entries are found for some file(s). In my case, I had duplicate entries for two files, I deleted one entry for each of the files, that solved my problem. Hope this helps.


That can happen if the same .m file is referenced multiple times in your target's "Compile Sources" section in "Build Phases". Remove duplicate entries and you should be fine.


In one case, I saw this error when dragging a new class' .h and .m into the project. The only solution I found was to remove the references to these files and then add them back via the project menu.


The only (and unfailing) way to resolve this issue is building test from command line:

xcodebuild -workspace MyProject.xcworkspace/ -scheme MyScheme -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.3.1' test

So, at this point, your compilation will surely fail but you'll see all linking problem. In my case, I had several problem such as:

  • ld: framework 'Foo' not found
    To resolve this, you need to on your target, BuildSettings->Linking->OtherLinkerFlags and remove 'Foo' framework .
  • Use of unresolved identifier 'ClassName' .
    To resolve this, I need to add/check file's target membership to UITest target too.

Other possible problems will be raised by xcodebuild and you can easily fix it.


I got this issue because I accidentally imported the .m instead of the .h. Hope reading this saves someone with same problem some time.


[XCODE 7.1 UPDATE]

First Option That Worked:

I changed the Deployment Target from 7.1 to 8.1 and the error went away.

Hope that helps someone.

UPDATE (day 2): Second time I'm back here in 2 days.

On day 2 I started to get more errors in addition to this annoying error. The problem was a conflicting file that Xcode didn't recognize. I used the links below as help:

  1. "_OBJC_CLASS_$_viewsampleViewController", referenced from:

  2. ‘ld: warning: directory not found for option’

And ultimately:

  1. "_OBJC_CLASS_$_viewsampleViewController", referenced from:

I was deleting everything from the FrameWork Search Paths + Compile Resources + Run Script Phases + the pods and then re-installing them again to ultimately find success.

The issue on my size (on day 2) was more of a problem with conflicting files or files that Xcode didn't recognize.

But ultimately, removing everything (mentioned above and in the links), cleaning a lot of times and reinstalling the pods/frameworks/run script phases helped.

Really hope this helps someone.


This occurred for me when I named a UILabel reference and an int the same thing, I didn't get an error when I typed it only when I tried to run it so I didn't realize that that was the problem, but if you have something like a label which is the "score" and you call it score, and name an int which is the score also score then this problem occurs.


Variations on this issue can occur if you have a missing library or file. Check there aren't any missing files in your Project Explorer: they'll be written in red if Xcode can't find them.


'linker command failed with exit code 1 (use -v to see invocation)'- I got this error when running a phonegap application on iPhone. I changed Build Active Architecture Only to Yes and it worked fine.


I had this same issue with a library, and I tried all of the answers listed here and nothing helped.

I ended up simply removing the library from Link Binary With Libraries and then re-adding it and it worked fine.


I got a similar error when adding files from another project, like @paiego explained. My error was that I didn't check "Add to targets". As explained above, I deleted the references and added the files again but this time checking "Add to targets".


"Link Binary With Libraries" had old project name pod library. Fixed after removal.

  1. List item
  2. Project
  3. Build Phases
  4. Link Binary With Libraries
  5. Remove deprecated library.

I'm posting a new answer to this because I ran into this error and had to use a different solution that I think is specific to iOS 9.

I had to explicitly disable the Enable Bitcode in Build Settings, which is automatically turned on in the update.

Referenced answer: New warnings in iOS 9


I had the same error. I had imported a audio frame work that i was no longer using. I removed it (DO NOT DELETE IT!) and it built successfully.


Examples related to objective-c

Adding a UISegmentedControl to UITableView Keep placeholder text in UITextField on input in IOS Accessing AppDelegate from framework? Warp \ bend effect on a UIView? Use NSInteger as array index Detect if the device is iPhone X Linker Command failed with exit code 1 (use -v to see invocation), Xcode 8, Swift 3 ITSAppUsesNonExemptEncryption export compliance while internal testing? How to enable back/left swipe gesture in UINavigationController after setting leftBarButtonItem? Change status bar text color to light in iOS 9 with Objective-C

Examples related to ios

Adding a UISegmentedControl to UITableView Crop image to specified size and picture location Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Keep placeholder text in UITextField on input in IOS Accessing AppDelegate from framework? Autoresize View When SubViews are Added Warp \ bend effect on a UIView? Speech input for visually impaired users without the need to tap the screen make UITableViewCell selectable only while editing Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

Examples related to xcode

Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64 iPhone is not available. Please reconnect the device Make a VStack fill the width of the screen in SwiftUI error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65 The iOS Simulator deployment targets is set to 7.0, but the range of supported deployment target version for this platform is 8.0 to 12.1 Xcode 10.2.1 Command PhaseScriptExecution failed with a nonzero exit code Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Xcode 10: A valid provisioning profile for this executable was not found Xcode 10, Command CodeSign failed with a nonzero exit code

Examples related to ios5.1

build failed with: ld: duplicate symbol _OBJC_CLASS_$_Algebra5FirstViewController