247
votes

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?

30
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.ravron
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
it's not your case, cause before I add the sdk of google my project build ok.lee
Second answer from Adam Waite is really straight forward. Make sure there is no .m file #imported somewhere.Bogdan
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.Hope

30 Answers

122
votes

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

277
votes

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

263
votes

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

59
votes

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";
35
votes

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

34
votes

Happens also when you declare const variables with same name in different class:

in file Message.m

const int kMessageLength = 36;

@implementation Message

@end

in file Chat.m

const int kMessageLength = 20;

@implementation Chat

@end
33
votes

I found the accepted answer touches on the problem but didn't help me solve it, hopefully this answer will help with this very frustrating issue.

duplicate symbol _OBJC_IVAR_$_BLoginViewController._hud in:

17 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:"

In layman's terms this means we have two files in our project with exactly the same name. Maybe you are combining one project into another one? Have a look at the errors above the "duplicate symbols" error to see which folder is duplicated, in my case it was BLoginViewController.

For example, in the image below you can see I have two BImageViewControllers, for me this is what was causing the issue.

As soon as I deleted one then the issue vanished :)

enter image description here

30
votes

This occurred on me when I accepted "recommended settings" pop-up on a project that I develop two years ago in Objective-C.

The problem was that when you accepted the "recommended settings" update, Xcode automatically changed or added some build settings, including GCC_NO_COMMON_BLOCKS = YES;.

This made the build failed with the duplicate symbol error in my updated project. So I changed No Common Block to NO in my build settings and the error was gone.

18
votes

Fastest way to find the duplicate is:

  1. Go to Targets
  2. Go to Build Phases
  3. Go to Compile Sources
  4. Delete duplicate files.
18
votes

I experienced this issue after installing Cocoapods. Now happens everytime I update some pods. Solution I've found:

Go to terminal:

1) pod deintegrate
2) pod install

Also, check the item "Always Embed Swift Libraries" in your Build Settings. It should be "faded" indicating it is using the default configuration. If its set to a manual YES, hit delete over it to revert it to the default configuration. This stopped the behavior.

15
votes

Following steps solved the issue for me.

  1. Go to Build Phases in Target settings.
  2. Go to “Link Binary With Libraries”.
  3. Check if any of the libraries exist twice.
  4. Build again.
14
votes
  • Go to Targets
  • Select Build Settings
  • Search for "No Common Blocks", select it to NO.

It worked for me

13
votes

Remove -ObjC from Other Linker Flags or Please check you imported any .m file instead of .h by mistake.

10
votes

My situation with some legacy project opened in Xcode 7.3 was:

duplicate symbol _SomeEnumState in:

followed with list of two unrelated files.o, then this was repeated couple of times, then finally:

ld: 8 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What solved it for me was changing enum declaration from:

enum SomeEnumState {
    SomeEnumStateActive = 0,
    SomeEnumStateUsed = 1,
    SomeEnumStateHidden = 2
} SomeEnumState;

to this:

typedef NS_ENUM(NSUInteger, SomeEnumState) {
    SomeEnumStateActive = 0,
    SomeEnumStateUsed = 1,
    SomeEnumStateHidden = 2
};

If somebody has explanation for this, please enlighten me.

9
votes

Defining same variable under @implementation in more than one class also can cause this problem.

9
votes

In my case, there were two file by same name in the location

Targets > Build Phases > Compile Sources and delete any duplicate files.

8
votes

Update answer for 2021, Xcode 12.X:

pod deintegrate 
pod install

Hope this helps!

6
votes

For me during the Xcode8 recommended project settings update "No Common Blocks" to YES which causes this issue.

5
votes

Today , I got the same error . The error's key word is duplicate. I fix it by:

1. Remove the duplicate file at Build Phases-->Compile Sources
2. If you can not remove it at Build Phases, you need find the file at your project and remove the reference by DELETE :

remove reference

3. Add the file to your project again
4. Add the file's .m to your Build Phases-->Compile Sources again
5. Build your project, the error will disappear
4
votes

Another silly mistake that will cause this error is repeated files. I accidentally copied some files twice. First I went to Targets -> Build Phases -> Compile sources. There I noticed some files on that list twice and their locations.

4
votes

Make sure you haven't imported a .m file by accident, you might want to delete your derived data in the Projects Window and then build and run again.

4
votes

I got the same error when I added a pod repository

pod 'SWRevealViewController'

for an already added source code (SWRevealViewController) from gitHub. So, the error will be fixed by either removing the source code or pod repository.

Case # 2:

The 2nd time, this error appeared when I declare a constant in .h file.

NSString * const SomeConstant  = @"SomeValue";
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
...
...
4
votes

For anyone else who is having this issue, I didn't see my resolution in any of these answers.

After having a .pbxproj merge conflict which was manually addressed (albeit poorly), there were duplicate references to individual class files in the .pbxproj. Deleting those from the Project > Build Phases > Compile Sources fixed everything for me.

Hope this helps someone down the line.

4
votes

Similar to Juice007, I had declared and initialized a C type variable in two different .m files (that weren't imported!)

BOOL myVar = NO;

however, this method of declaring and initializing a variable, even in .m, even in @implementation grants it global scope. Your options are:

  1. Declare it as static, to limit the scope to class:

    static BOOL myVar = NO;
    
  2. Remove the initialization (which will make the two classes share the global var):

    BOOL myVar;
    -(void) init{
        myVar = NO;
    }
    
  3. Declare it as a property:

    @property BOOL myVar;
    
  4. Declare it as a proper iVar in the @interface

    @interface myClass(){
        BOOL myVar;
    }
    @end
    
4
votes

In my case I had two main() methods defined in my project and removing one solved the issue.

4
votes

The answers above didn't work for me. Here's how I got around it:

1) in finder, delete the entire Pods folder and Podfile.lock file 2) close the xcode project 3) run pod install in the terminal 4) open the xcode project, run the clean build command

Worked for me after that.

4
votes

Because I haven't seen this answer:

Uninstall and reinstall your podfiles! Remove or uninstall library previously added : cocoapods

I've run into this issue over 3 times building my app and every time this is what fixes it. :)

3
votes

Same issue happen with me, when I was integrating the lob project inside my project.

enter image description here

Actually lob project also have the AFNetworking files, So I remove the .m files from lob project.

enter image description here

Actually .m files are conflicting with My project POd/AFNetworking/ .m files

enter image description here

3
votes

Recently had a headache looking for source of an error. I was wondered, when i found out that my app doesn't want to compile, simply because i had following code snippet in different classes:

dispatch_time_t getDispatchTimeByDate(NSDate *date)
{
    NSTimeInterval interval;
    double second, subsecond;
    struct timespec time;
    dispatch_time_t milestone;


    interval = [date timeIntervalSince1970];
    subsecond = modf(interval, &second);
    time.tv_sec = second;
    time.tv_nsec = subsecond * NSEC_PER_SEC;
    milestone = dispatch_walltime(&time, 0);

    return milestone;
}

Hope that might help someone.

3
votes

I hope it will definitely help you

I got same error 3 duplicate symbols for architecture x86_64

in my case I have copied code from another file of same project eg. code of A.m file to B.m and after complilation i got an error as mention. and i have solve error by changing the name of global Variable.

this error came in my case because of same declare for global variable in both file.