duplicate symbols for architectures in Xcode

50,309

Solution 1

In your build phases, check to see that you aren't compiling the same file more than once. i.e. If you search for main.m it should only return one result.

If that's not the problem, can you add the code from your main.m to the question?

Solution 2

Check your import files, it may that you're importing a .m file.

#import "TimeModel.m"

Solution 3

Although the following is not the cause in the OP's case, it was mine, so I'll share it here for anyone facing the same error:

If you are getting a linker error on all global variables, you might need to add extern to their declarations in your header files.

Whether the lack of extern will generate this issue is dependent on build settings, more specifically on "No Common Blocks" under "Apple LLVM - Code Generation" (GCC_NO_COMMON_BLOCKS, -fno-common). If set to yes, which is the default in newer versions of Xcode, you'll get a linker error without extern.

Why extern?

The extern keywords makes it a declaration only (i.e. not also a definition), which since it's a header file is what you want. Some compilers allow it without extern and still 'do the right thing', but omitting extern is discouraged. Which is why newer versions of Xcode by default enable the warning.

Solution 4

Here is a situation in Xcode 7.0 with duplicate symbols error, in case anyone else comes across this scenario

.h file

NSUserDefaults *defaults; // <----placing this above the @interface caused the issue

@interface someViewController

//...

Change to

.h file

@interface someViewController

{
   NSUserDefaults *defaults;
}

//...

Solution 5

This could happen also when you have the same @interface in different files with different implementations. For example you have a Player class, in the Player.h/m files and you have a Match class (Match.h/m), and a match is between two player, but not the aforementioned Player.

Player.h

@interface Player : NSObject
@property (nonatomic) NSUInteger _id;
@property (nonatomic, strong) NSString* firstName;
@property (nonatomic, strong) NSString* lastName;
@property (nonatomic, strong) NSString* username;
@end

Match.h

@class Player

@interface Match : NSObject
@property (nonatomic, strong) Player* player1;
@property (nonatomic, strong) Player* player2;
@property (nonatomic) NSUInteger matchId;
@end

@interface Player : NSObject
@property (nonatomic, strong) NSString* nickName;
@property (nonatomic, strong) NSString* point;
@property (nonatomic, strong) NSNumber* lastMove;
@end

In this case the the compiler see two different Player class implementation. You need to refactor the Player class in the Match.h file to MatchPlayer.

Share:
50,309
IlyaKharlamov
Author by

IlyaKharlamov

Updated on January 06, 2020

Comments

  • IlyaKharlamov
    IlyaKharlamov over 4 years

    Here is the error message I receive when compiling ...

    Ld /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Products/Debug-iphonesimulator/MasterDetail.app/MasterDetail normal i386
        cd /Users/ilia3546/Проекты/iDecide
        setenv IPHONEOS_DEPLOYMENT_TARGET 5.0
        setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk -L/Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Products/Debug-iphonesimulator -F/Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Products/Debug-iphonesimulator -filelist /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetail.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=5.0 -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Products/Debug-iphonesimulator/MasterDetail.app/MasterDetail
    
    duplicate symbol _main in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/main-E0BAF2CA88EDEE32.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailAppDelegate._window in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailAppDelegate-C2C06F734ECE2E36.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailAppDelegate._navigationController in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailAppDelegate-C2C06F734ECE2E36.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailAppDelegate._splitViewController in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailAppDelegate-C2C06F734ECE2E36.o
    duplicate symbol _OBJC_CLASS_$_MasterDetailAppDelegate in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailAppDelegate-C2C06F734ECE2E36.o
    duplicate symbol _OBJC_METACLASS_$_MasterDetailAppDelegate in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailAppDelegate-C2C06F734ECE2E36.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailDetailViewController._detailItem in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailDetailViewController-B3C32DC7B1BE4E38.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailDetailViewController._TitleOfDetail in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailDetailViewController-B3C32DC7B1BE4E38.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailDetailViewController._detailDescriptionLabel in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailDetailViewController-B3C32DC7B1BE4E38.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailDetailViewController._masterPopoverController in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailDetailViewController-B3C32DC7B1BE4E38.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailDetailViewController.WebView in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailDetailViewController-B3C32DC7B1BE4E38.o
    duplicate symbol _OBJC_CLASS_$_MasterDetailDetailViewController in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailDetailViewController-B3C32DC7B1BE4E38.o
    duplicate symbol _OBJC_METACLASS_$_MasterDetailDetailViewController in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailDetailViewController-B3C32DC7B1BE4E38.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailMasterViewController._detailViewController in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailMasterViewController._Controller1 in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailMasterViewController.listOfDecide in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailMasterViewController.listOfDecideOpis in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailMasterViewController.listOfGraph in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailMasterViewController.listOfGraphOpis in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailMasterViewController.listOfAbout in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_IVAR_$_MasterDetailMasterViewController.listOfAboutOpis in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_CLASS_$_MasterDetailMasterViewController in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    duplicate symbol _OBJC_METACLASS_$_MasterDetailMasterViewController in:
        /Users/ilia3546/Library/Developer/Xcode/DerivedData/MasterDetail-fhgogwnbpzovbtaskgecptdnvgjs/Build/Intermediates/MasterDetail.build/Debug-iphonesimulator/MasterDetail.build/Objects-normal/i386/MasterDetailMasterViewController-A4C5EC1C14AE6E3A.o
    ld: 23 duplicate symbols for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    appdelegate.m -

    #import "MasterDetailAppDelegate.h"
    
    #import "MasterDetailMasterViewController.h"
    
    #import "MasterDetailDetailViewController.h"
    
    
    @implementation MasterDetailAppDelegate
    
    @synthesize window = _window;
    @synthesize navigationController = _navigationController;
    @synthesize splitViewController = _splitViewController;
    
    - (void)dealloc
    {
        [_window release];
        [_navigationController release];
        [_splitViewController release];
        [super dealloc];
    }
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
                MasterDetailMasterViewController *masterViewController = [[[MasterDetailMasterViewController alloc] initWithNibName:@"MasterDetailMasterViewController_iPhone" bundle:nil] autorelease];
                self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
                self.window.rootViewController = self.navigationController; 
        } else {
            MasterDetailMasterViewController *masterViewController = [[[MasterDetailMasterViewController alloc] initWithNibName:@"MasterDetailMasterViewController_iPad" bundle:nil] autorelease];
            UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
    
            MasterDetailDetailViewController *detailViewController = [[[MasterDetailDetailViewController alloc] initWithNibName:@"MasterDetailDetailViewController_iPad" bundle:nil] autorelease];
            UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
            self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
            self.splitViewController.delegate = detailViewController;
            self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
    
            self.window.rootViewController = self.splitViewController;
        }
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application
    {
        /*
         Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
         Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
         */
    }
    
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        /*
         Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
         If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
         */
    }
    
    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        /*
         Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
         */
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        /*
         Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
         */
    }
    
    - (void)applicationWillTerminate:(UIApplication *)application
    {
        /*
         Called when the application is about to terminate.
         Save data if appropriate.
         See also applicationDidEnterBackground:.
         */
    }
    
    @end
    

    main.m -

    //
    //  main.m
    //  MasterDetail
    //
    //  Created by Wei-Meng Lee on 3/9/11.
    //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    #import "MasterDetailAppDelegate.h"
    
    int main(int argc, char *argv[])
    {
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([MasterDetailAppDelegate class]));
        }
    }
    

    I checked importing the .m file instead of the .h, but all correctly.

    • stark
      stark over 11 years
      Check for dups in <reallylongppath>MasterDetail.LinkFileList
    • deanWombourne
      deanWombourne over 11 years
      Can you add the source code for MasterDetailAppDelegate.m as well - it looks like it's somehow defining things twice in that file?
  • IlyaKharlamov
    IlyaKharlamov over 11 years
    Thanks, main.m and other .m files was repeated for some reason!
  • deanWombourne
    deanWombourne over 11 years
    Yea, it happens sometimes to me too - I have no idea why but I've learned that's the first place to look when you see a duplicate symbol error from the linker :)
  • Matt Hudson
    Matt Hudson almost 11 years
    Thank goodness for this answer. I was taring my hair out. :)
  • Oscar
    Oscar over 10 years
    OK, but what's the solution?
  • deanWombourne
    deanWombourne over 10 years
    In this case, don't have duplicate files in the compile build phase - otherwise the linker will just report duplicate symbols. select one of your duplicates and press delete.
  • EarlGrey
    EarlGrey over 9 years
    oh yeah, my hair was almost out as well. plus one here.
  • Jacksonkr
    Jacksonkr over 9 years
    Out 68 listings 5 of them were duplicates. In my HOURS of scouring the web I've seen this answer a few times and it wasn't until I tried to search ALL the items that I found the few culprits. What a pain..
  • Mihir Mehta
    Mihir Mehta over 9 years
    I am facing same issue but my problem is that on definition resides in .a file and one in .framework ... what can i do?
  • deanWombourne
    deanWombourne over 9 years
    That means that you have a symbol that's the same in both the .a and the framework - it's probably unlucky coincidence (or they have both linked in a seperate library, which is incredibly annoying). The best way to fix this is post a question on stack overflow with all the details (i.e. linker errors, framework names etc - someone might have the same problem you do :)
  • Typewriter
    Typewriter almost 9 years
    Me = tired programmer = silly mistake. Thanks. (Clang, can't you give us a better error than this!?)
  • Typewriter
    Typewriter almost 9 years
    And NOW, code completion keeps auto-entering ".m" when I try to import that class. Haha, sigh.
  • warzone_fz
    warzone_fz over 8 years
    Sir , you are a genius :D
  • physicalattraction
    physicalattraction about 8 years
    This is what happened to me when I was removing references and adding them again. I would have never guessed if it were not for this answer!
  • mkabatek
    mkabatek almost 8 years
    Awesome, thank you for posting this. I Imported a project into a newer version of xcode, and was seeing this error - kudos!
  • pAkY88
    pAkY88 almost 8 years
    Thank you! You saved my life! ;)
  • RyanJM
    RyanJM over 7 years
    I'm not sure why this didn't show up earlier for me. This showed up when upgrading to Xcode 8.
  • Dave S
    Dave S over 7 years
    Ran into this issue when forced to target iOS 8 after upgrading Xcode.
  • Gustanas
    Gustanas over 7 years
    After hours of work, this finally fixed the issue I was having... What's the reason for putting 'extern' btw?
  • rmvz3
    rmvz3 about 7 years
    Yes! This is the right answer in my case. Thank you
  • Duck
    Duck over 6 years
    wow! how crappy xcode is! It does not check for duplicates before compiling?
  • Duck
    Duck over 6 years
    I LOVE YOU!! 😃
  • deanWombourne
    deanWombourne over 6 years
    @SpaceDog Just checking for duplicate files will only solve one of the ways this problem can occur - this problem is far more likely to be defining the same symbol in two files you're linking into the same binary, which can only really be reliably detected when linking. Given how unlikely it is that you get a file entered twice in the build phase, they probably did a quick cost/benefit analysis and decided that the extra code was't worth the maintenance / testing cost. Xcode probably has bugs with much more impact they need to fix first.
  • nickdnk
    nickdnk over 5 years
    It's fascinating how many times I've made this mistake while not remembering that this is the problem.
  • Jan Moritz
    Jan Moritz over 4 years
    In my case I included a .cpp file, this causes the same problem