duplicate symbols for architecture i386 clang

后端 未结 24 1059
悲哀的现实
悲哀的现实 2020-11-29 20:33

I\'ve seen several posts on google and stackoverflow related to this error, I\'ve read all of them but still fetching the problem , I will be glad for a solution. Here is th

相关标签:
24条回答
  • 2020-11-29 20:44

    I just experienced this after recreating a model class for Core Data. The menu option to create object classes created a duplicate model class. once i removed the dupe, error gone...

    0 讨论(0)
  • 2020-11-29 20:45

    Note to self: "READ THE ERROR!"

    In my case it says this: duplicate symbol _OBJC_CLASS_$_SATCoreData in:

    Translation: an Objective C Class called SATCoreData is duplicated.

    Then it gives the path to both occurrences of the symbol. Reading the path points to the two the class file ending in .o. If you look at both classes you will find something fishy. In my case I had accidently given two classes the same name. One class I had inside the file of another class because I was testing something and was too lazy to make a separate class. Hope this helps someone.

    0 讨论(0)
  • 2020-11-29 20:46

    Go to Build Setting and search for No Common Blocks and set it NO. And build again you will not get this error again.

    0 讨论(0)
  • 2020-11-29 20:47

    Taken from https://stackoverflow.com/a/2755581/190599

    What you can do is put in your header (MyConstants.h):

    extern const int MyConstant;
    extern NSString * const MyStringConstant;
    

    And in a source file, include the header above but define the constants (MyConstants.m):

    const int MyConstant = 123;
    NSString * const MyStringConstant = @"SomeString";
    

    Then, you simply need to include the header in any other source file that uses either of these constants. The header is simply declaring that these constants exist somewhere, so the compiler won't complain, because it's the linker's job to resolve these constant names. The source file that contains your constant definitions gets compiled, and the linker sees that this is where the constants are, and resolves all of the references found in the other source files.

    The problem with declaring and defining a constant in a header (that is not declared as static) is that the compiler treats it as an independent global for each file that includes that header. When the linker tries to link all of your compiled sources together it encounters the global name as many times as you have included MyConstants.h.

    0 讨论(0)
  • 2020-11-29 20:48

    Steps:

    1. Check Build phases in Target settings.
    2. Check if any file exists twice or once.
    3. If file exist twice delete one. If not delete file in the bottom which is the latest one.
    4. Build again.
    0 讨论(0)
  • 2020-11-29 20:49

    I found that I was getting the error when I had a const declared in a .m file with the same name as another const in another .m file. Both files #included the same parent file.

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