Duplicate symbols for architecture x86_64 under Xcode

352,485

Solution 1

75 duplicate symbols for architecture x86_64

Means that you have loaded same functions twice. As the issue disappear after removing -ObjC from Other Linker Flags, this means that this option result that functions loads twice:

from Technical Q&A

This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes.

https://developer.apple.com/library/content/qa/qa1490/_index.html

Solution 2

For me, changing 'No Common Blocks' from Yes to No ( under Targets->Build Settings->Apple LLVM - Code Generation ) fixed the problem.

Solution 3

Stupid one, but make sure you haven't #imported a .m file by mistake somewhere

Solution 4

In my case, I just created a header file to define constant strings like this:

NSString *const AppDescriptionString = @"Healthy is the best way to keep fit";

I solved this scenario by using static:

static NSString *const AppDescriptionString = @"Healthy is the best way to keep fit";

Solution 5

I have same problem. In Xcode 7.2 in path Project Target > Build Setting > No Common Blocks, i change it to NO.

Share:
352,485

Related videos on Youtube

lee
Author by

lee

love Swift and Go!

Updated on April 01, 2022

Comments

  • lee
    lee about 2 years

    I now have the same question with above title but have not found the right answer yet. I got the error:

        /Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Intermediates/TestMoboSDK-Client.build/Debug-iphonesimulator/TestMoboSDK-Client.build/Objects-normal/x86_64/MoboSDK.o
        /Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Products/Debug-iphonesimulator/libMoboSDK.a(MoboSDK.o)
    duplicate symbol _OBJC_METACLASS_$_MoboSDK in:
        /Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Intermediates/TestMoboSDK-Client.build/Debug-iphonesimulator/TestMoboSDK-Client.build/Objects-normal/x86_64/MoboSDK.o
        /Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Products/Debug-iphonesimulator/libMoboSDK.a(MoboSDK.o)
    ld: 75 duplicate symbols for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    Any help is appreciated.

    Finally I find out the reason of this error cause I added -ObjC to the Other Linker Flags. After remove this value then I can build my project successfully, but I don't know why. Can anyone explain this?

    • ravron
      ravron about 10 years
      The linker has encountered symbols defined more than once - 75, to be exact. This is likely because you #include'd or #import'd something (likely the MoboSDK, whatever that is) more than once.
    • lee
      lee about 10 years
      this error happen after I add GoogleConversionTrackingSDK-iOS-3.0 into my project.Before that, it's work ok.I also tried to remove it, but the error still happen.
    • lee
      lee about 10 years
      it's not your case, cause before I add the sdk of google my project build ok.
    • Bogdan
      Bogdan over 8 years
      Second answer from Adam Waite is really straight forward. Make sure there is no .m file #imported somewhere.
    • Hope
      Hope almost 8 years
      In my case I was trying to use same string array name in two separate classes. When I have changed the array name in one of the classes this error has been removed.
    • doxsi
      doxsi over 7 years
      Make sure you #include a .h file, not a .m.
    • Alok
      Alok over 7 years
    • David Ferris
      David Ferris over 6 years
      A very similar error is thrown by accidentally including a .cpp file instead of it's corresponding header file .hpp!
    • Hanz Cheah
      Hanz Cheah about 6 years
      I have tried most of the suggested solutions below but I still have the error, can anyone please help. 1. I didn't find any duplicate files at Targets > Build Phases > Compile Sources 2. I changed the No Common Data to No, not working 3. I deleted all the derived data, clean and rebuild, Failed. stackoverflow.com/questions/49669403/…
    • yuchen
      yuchen over 2 years
      Worked perfect for me!
  • Reuben Tanner
    Reuben Tanner over 9 years
    In other words, make sure you remove any object files in your xcode project.
  • JanB
    JanB over 9 years
    Huge help, thank you. I have taken a backup of a project that uses cocoapods. In forgetting I needed to open the workspace when I reloaded the backup in Xcode and found it wouldn't build, I then added AFNetworking directly to the project. I subsequently went on to re-setup my cocoapods, which included AFNetworking as a dependency and forgot to remove the original AFNetworking folder that I had added to my project.
  • user1244109
    user1244109 almost 9 years
    this solved the issue for me. Although i prefixed extern instead of static : extern NSString * const kNotificationName;. Which is strange, because u usually did not add such prefix, and it worked fine..
  • Hemang
    Hemang almost 9 years
    This solved my problem. Is it ever require to change it back to NO ? What's the reason behind this ?
  • Linda MacPhee-Cobb
    Linda MacPhee-Cobb almost 9 years
    If I were writing functional code in Swift I wouldn't want any common blocks of code, but writing OOP/MVC code in ObjC sometimes it makes sense to have duplicated blocks ( I have both metric and imperial functions that calculate similar things in many of my fitness apps )
  • bgplaya
    bgplaya over 8 years
    Hey, everybody, who is still wondering why -ObjC flag doesn't work - pay attention to this answer. I was completely wrong thinking -ObjC flag doesn't work in my "super special" case. After searching through the project for smth like .m" I have noticed that I did import .m file instead of .h and after fixing that it just worked! Talk is cheap, show me the code! Cheers!
  • Allison
    Allison over 8 years
    This, for some reason, solved my issue. Thanks. I don't understand why the compiler couldn't give out a better response than duplicate symbols, which doesn't seem related at all.
  • Sauvik Dolui
    Sauvik Dolui over 8 years
    @Sirens, I also expected a better error message from the LLVM compiler. Anyway I was lucky enough to find out the error after 2 days. :(
  • Fatlad
    Fatlad over 8 years
    this was my problem as well why is the actual problem caused by this?
  • Steven A. Lowe
    Steven A. Lowe over 8 years
    small helper function, accidentally copied, easily overlooked - thanks!
  • coco
    coco over 8 years
    Yes this solves the problem, but not the reason behind it. If you defined a const, make sure that definiton is ok. In my case I simply forgot "extern". This is mentioned in Sauvik Dolui answer.
  • Oktay
    Oktay over 8 years
    Not const but it worked for me when I change variable name
  • trojanfoe
    trojanfoe over 8 years
    This is fine if all the variables in AppStrings.h are constants, however it will cause havok if you want a global mutable variable as every source file that includes the header file will have their own copy of the variable. It's a bad solution.
  • Yawar
    Yawar about 8 years
    I don't know why someone downvoted you, this solved my issue.
  • Sunil Targe
    Sunil Targe almost 8 years
    It also work for me too, but my other libraries are depends on -ObjC flag. So I must need to keep this flag in my project settings. So could you please suggest any other solution?
  • David V
    David V almost 8 years
    I guess you need to review all your libraries: If you get duplicate linker error, that means you have same source code in 2 or more libraries.
  • Mark24x7
    Mark24x7 over 7 years
    Same thing fixed it for me, when I switched enum to typedef NS_ENUM it fixed the duplicate symbols error
  • pkamb
    pkamb over 7 years
    Xcode 8 prompted this change as one of its automatic updates and broke my build :/
  • Scooter
    Scooter over 7 years
    I hadn't done this, but this solution helped me find what I had done which was to declare a variable outside the @interface block in a .h file by mistake.
  • Pankaj Yadav
    Pankaj Yadav over 7 years
    Case 2nd saved me a night. Thanks!
  • vib
    vib over 7 years
    but why? same happened to me with plain C functions with same names
  • Zoltán
    Zoltán over 7 years
    Yeah, this helped me. Xcode 8, updated an older project to recommended settings. Switched this back and I'm good to go again. Thanks!
  • Helen Wood
    Helen Wood over 7 years
    Good job. Helped me a lot! An up vote for you darling! ;-)
  • onekiloparsec
    onekiloparsec over 7 years
    Same here for Xcode8.2.1, when applied to an old project.
  • Coty Embry
    Coty Embry about 7 years
    I had to remove some of the React libraries it was complaining about under Target->Build Phases->Link Binary With Libraries in Xcode since it was conflicting with my cocoa pods install of React
  • Manish Pathak
    Manish Pathak about 7 years
    After spending 2 hour, this issue has been resolved because of this answer. Thanks
  • Muju
    Muju almost 7 years
    Worked for me as well. Thanks.
  • Bruno Muniz
    Bruno Muniz almost 7 years
    When using unit tests, only the .m file is generated. I created a header file for it despite i guess this is not the best solution - i wanted to create a base test class.
  • Ky -
    Ky - almost 7 years
    @user1244109 static is for when you actually have a value (static NSString * kFoo = @"Foo";) and extern is for when you are just saying "this constant exists but its value is defined in the .m/.c/etc. (extern NSString * kFoo;). Also, I recommend using FOUNDATION_EXPORT because it adapts to different compilation environments (ObjC, ObjC++, Win32, etc.)
  • Daniel Lima
    Daniel Lima over 6 years
    Thank you so much for enlightening my mind for the possibility that I made such a stupid mistake.
  • ammianus
    ammianus over 6 years
    I had this with a pointer of my own class variable defined in the @implementation of two different classes
  • Burf2000
    Burf2000 over 6 years
    Brilliant mate :)
  • Axeman
    Axeman over 6 years
    Xcode 9 automatically changed it in automatic update of an old project. Restored to "NO" and build succeeded.
  • kas-kad
    kas-kad over 6 years
    also had merging conflicts and had to manually resolve them in pbxproj file. Ended up with ld: X duplicate symbols for architecture x86_64. Fixed it by removing the source files mentioned in error message and re-adding them again to the project.
  • Ravi
    Ravi over 6 years
    In my case I have import .m file. So stupid mistake. Once I imported .h file. It is ready for build!! Thanks
  • PANKAJ VERMA
    PANKAJ VERMA over 6 years
    At compile time, compiler checks for duplicate symbols (here global variables) only in header(.h) files. But at linking time the (global) variables in implementation(.m) files are also checked and if there any duplicate, Linker will through error : duplicate symbol _xyz
  • Abdullah Nurum
    Abdullah Nurum over 6 years
    Fantastic. I wasted two days to solve this problem. This worked for me. Thanks a lot.
  • Nooblhu
    Nooblhu about 6 years
    This works, but I had to change it in target and project
  • Shivani Gor
    Shivani Gor about 6 years
    After spending my whole day, this issue has been resolved because of this answer. Thanks a lot!!!
  • swift2geek
    swift2geek almost 6 years
    Thank you man!!!!, it solved my issue. 4 days of removing duplicates....and bam - this solution
  • Tina
    Tina almost 6 years
    After searching for an hour,This answer helped me a lot Thanks
  • noveleven
    noveleven over 5 years
    how about cross-project import .m file?
  • Baran Emre
    Baran Emre about 5 years
    Had the same problem here. Your post helped me. Thanks!
  • I make my mark
    I make my mark almost 5 years
    What does it do?
  • CJ_COIMBRA
    CJ_COIMBRA over 4 years
    Add a couple more hours to that.
  • LowFieldTheory
    LowFieldTheory over 4 years
    This fixed it on XCode 11.3.1 too
  • Kilo Loco
    Kilo Loco over 4 years
    I've also been running into this a lot more lately. Not sure if it has something to do with Xcode 11 or Catalina but this is what usually fixes my project as well. 1. Open your Podfile 2. Comment out ALL your pods 3. Run pod install 4. Uncomment your pods in the Podfile 5. Run pod install again 6. Profit
  • Kasey
    Kasey over 4 years
    @kiloLoco Yeah I think it's a bug in Xcode? Maybe I'm wrong.
  • foufrix
    foufrix over 4 years
    In xcode 10 it's now under Apple Clang - Code Generation Thanks !
  • BVB09
    BVB09 about 4 years
    This worked for me. However, "Always Embed Swift Libraries" was already set to NO. I switched it to YES and then hit delete and then ran the pod functions stated above.
  • tong
    tong about 4 years
    Thanks! In my case I compiled two main.m where one was the old reference. This was caused by drag and drop.
  • Naresh
    Naresh almost 4 years
    which is only for class files like .h, .m or .swift files. Not for frame work level files.
  • shokaveli
    shokaveli over 3 years
    This is the answer! SwiftUI previews was not working for me until I made this change. Thx sir!
  • Chandni
    Chandni over 3 years
    Where can I have this option?
  • bdroid
    bdroid over 3 years
    Legacy Build System Deprecated
  • Farras Doko
    Farras Doko over 3 years
    Just need to import .h file 🙃
  • Bitlejuce Do
    Bitlejuce Do about 3 years
    I had to rename even local variables @implementation DIOOutstreamVideoView CGFloat visibleHeightOut; CGFloat fullHeightOut;
  • Jafar Jabr
    Jafar Jabr over 2 years
    Thank you, it didn't solve my problem but decreased the duplications from 14 to 9
  • Jafar Jabr
    Jafar Jabr over 2 years
    the rest solved by removing "use_flipper!()" from podFile
  • Kalamarico
    Kalamarico over 2 years
    I'm glad to hear that!! And thanks for your input!
  • Josue Gisber
    Josue Gisber about 2 years
    This was the easiest way. Thanks! I was having that problem with a c code and I follow this steps and it work. Although I have to clarify that don't delete the file with your main function because it won't work.
  • Just a coder
    Just a coder about 2 years
    That was it for me. I copied and pasted one app into another, and forgot the pasted SwiftUI app had its own @main entry. Therefore 2 entry points to my app.
  • Tim Sonner
    Tim Sonner about 2 years
    I tried switching the build setting flag, didn't work. I tried creating a new header file, importing the .h instead of .m, and placing the contents of my .m file inside the header file and it worked.
  • Anirban Das
    Anirban Das about 2 years
    Thanks! man. Atlast for your answer I'm able to run the app for first time... Thank you very much!!!