build failed with: ld: duplicate symbol _OBJC_CLASS_$_Algebra5FirstViewController

199,018

Solution 1

It look like the class Algebra5FirstViewController is compile multiple time.

Can you make sure that the .m and .mm is only included once in your project sources in Xcode? You can also confirm this by checking in the compile log (last icon at the right, next to the breakpoints icon) and see that confirm that it is only compiled once.

Also, if this class is part of a library that you link against and you have a class with the same name, you could have the same error.

Finally, you can try a clean and rebuild, just in case the old object files are still present and there is some junk in the compiled files. Just in case...

EDIT

I also note that the second reference is made in the file for ExercisesViewController. Maybe there is something in this file. Either you #imported the Algebra5FirstViewController file instead of the .h, or the ExercisesViewController has @implementation (Algebra5FirstViewController) instead of @implementation (ExercisesViewController), or there was some junk with this file that will cleaned with a Clean an Rebuild.

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

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

Share:
199,018
Joe Shamuraq
Author by

Joe Shamuraq

A newbie in iOS... From basic php environment

Updated on July 05, 2022

Comments

  • Joe Shamuraq
    Joe Shamuraq almost 2 years

    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?

  • NathanChristie
    NathanChristie over 11 years
    This ultimately was my problem, but was limited to the simulator only - it worked fine when compiling / executing on my phone.
  • Ryan Wheale
    Ryan Wheale over 10 years
    ... or if a .m file used in code is NOT referenced in the "Compile Sources" - as was my situation.
  • Jeff Ames
    Jeff Ames about 8 years
    autocomplete importing the .m file instead of the .h is what caused the issue for me