Duplicate Symbol Error in Objective-C build?

前端 未结 17 1851
礼貌的吻别
礼貌的吻别 2020-11-27 14:12

I got this error when I press build+debug:

ld: duplicate symbol .objc_class_name_BlogTableItemCell in /Users/fabian/Development/Workspaces/iphone_experiments         


        
相关标签:
17条回答
  • 2020-11-27 15:07

    Adding another possible cause to the list... you may have mistakingly created multiple constants in the implementation file, but outside of the implementation, with the same name.

    In HeaderFileOne.m

    NSString * const kCoolConstant = @"cool";
    

    In HeaderFileTwo.m

    NSString * const kCoolConstant = @"cool";
    

    So changing one of those constant names would fix the compile error.

    0 讨论(0)
  • 2020-11-27 15:07

    The same thing happened to me while I was playing with localizable xib files, accidentally I have created two implementation files and appereantly that caused the problem in my case. After deleting / recreating the implementation file without doing the same mistake, the error was fixed.

    0 讨论(0)
  • 2020-11-27 15:08

    I had a similar problem due to poor defining of consts. I had defined a const in my header:

    int const kCropLocationTop = 1;
    

    This was presumably imported multiple times. To fix i changed the header def as follows:

    extern int const kCropLocationTop;
    

    and moved the assigning of the const to the .m file:

    int const kCropLocationTop = 1;
    

    Hope that helps anyone who's as ignorant of simple objective c concepts as I am!

    0 讨论(0)
  • 2020-11-27 15:09

    I also faced to this problem. My solution was rename one of global variable, which has the same name as one in other class. Hope this helps

    0 讨论(0)
  • 2020-11-27 15:14

    You could also get this error if you mistakenly let Xcode's auto-complete for #import statements specify the '.m" file for the 'duplicate' class instead of the '.h'.

    0 讨论(0)
  • 2020-11-27 15:14

    It happened to me, too. In my case, one (just one) of my core data automatically generated classes was inserted twice. I spotted the duplication by looking at Build Phases...Compile Sources. Simply deleting one of the occurrences solved the problem.

    0 讨论(0)
提交回复
热议问题