Search code examples
iosobjective-cmach-o

Apple Mach-O Link


I got an error while compiling my code. The issue identifier labels it as 'Apple Mach-O Link Linker command failed'. I have no clue what this is so I have not been able to find a solution.

duplicate symbol _OBJC_METACLASS_$_XYZFlipsideViewController in:
    /Users/studentuse/Library/Developer/Xcode/DerivedData/RSC-      
aardgrngtzicssfffcbdqsezpqmv/Build/Intermediates/RSC.build/Debug-    
iphonesimulator/RSC.build/Objects-normal/i386/XYZAppDelegate.o
    /Users/studentuse/Library/Developer/Xcode/DerivedData/RSC-  
aardgrngtzicssfffcbdqsezpqmv/Build/Intermediates/RSC.build/Debug-
iphonesimulator/RSC.build/Objects-normal/i386/XYZFlipsideViewController.o
ld: 6 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation) //This    
line has the mistake

What is the problem with the code?

(This is only part of the code.)


Solution

  • The problem is that you have defined the implementation of the class XYZFlipsideViewController twice, and the linker can't figure out which definition you meant:

    duplicate symbol _OBJC_METACLASS_$_XYZFlipsideViewController
    

    The two places it is defined in are these two object files:

    XYZAppDelegate.o
    XYZFlipsideViewController.o
    

    There are two possible explanations:

    • You have a @implementation XYZFlipsideViewController ... @end block in both of the source files XYZAppDelegate.m and XYZFlipsideViewController.m, or
    • You have the @implementation ... @end block inside a header file which is #include/#imported by both of those source files

    In the first case, the solution is to remove one of the @implementation blocks. In the second case, the solution is to move the @implementation block from the header into the source file, but keep the @interface block in the header file.

    It's important to understand the distinction between @interface and @implementation -- the former says "Here is the name of a class, the names of its instance variables, and the names of its member functions", whereas the latter says "Here are all the definitions of the class's properties and member functions".