Xcode 中架构的重复符号

Posted

技术标签:

【中文标题】Xcode 中架构的重复符号【英文标题】:duplicate symbols for architectures in Xcode 【发布时间】:2012-10-20 13:39:04 【问题描述】:

这是我在编译时收到的错误消息...

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]));
    

我检查了导入 .m 文件而不是 .h,但都正确。

【问题讨论】:

检查 MasterDetail.LinkFileList 中的重复数据 您能否也添加MasterDetailAppDelegate.m 的源代码 - 看起来它以某种方式在该文件中定义了两次? 【参考方案1】:

检查您的导入文件,您可能正在导入 .m 文件。

#import "TimeModel.m"

【讨论】:

感谢上帝的回答。我正在梳理头发。 :) 哦,是的,我的头发也快掉光了。在这里加一个。 我 = 累了的程序员 = 愚蠢的错误。谢谢。 (Clang,你能不能给我们一个比这更好的错误!?) 现在,当我尝试导入该类时,代码完成会自动输入“.m”。哈哈,叹气。 谢谢!你救了我的命! ;)【参考方案2】:

在您的构建阶段,检查您是否多次编译同一个文件。即,如果您搜索 main.m,它应该只返回一个结果。

如果这不是问题,您能否将 main.m 中的代码添加到问题中?

【讨论】:

谢谢,main.m 和其他 .m 文件由于某种原因被重复了! 是的,它有时也会发生在我身上——我不知道为什么,但我知道当你从链接器中看到重复符号错误时,这是​​第一个看的地方:) 好的,但是解决办法是什么? 在这种情况下,不要在编译构建阶段有重复的文件 - 否则链接器只会报告重复的符号。选择其中一个重复项,然后按删除。 在 68 个列表中,有 5 个是重复的。在我搜索网络的几个小时中,我已经多次看到这个答案,直到我尝试搜索所有项目,我才找到了几个罪魁祸首。好痛啊。。【参考方案3】:

虽然以下不是 OP 的原因,但它是我的,所以我会在这里分享给遇到同样错误的人:

如果您在所有全局变量上都收到链接器错误,您可能需要将 extern 添加到头文件中的声明中。

缺少 extern 是否会产生此问题取决于构建设置,更具体地说,取决于“Apple LLVM - 代码生成”下的“No Common Blocks”(GCC_NO_COMMON_BLOCKS,-fno-common)。如果设置为 yes,这是较新版本 Xcode 中的默认设置,如果没有 extern,您将收到链接器错误。

为什么选择外部?

extern 关键字使它只是一个声明(即不是一个定义),因为它是一个头文件,所以你想要什么。一些编译器允许它不使用 extern 并且仍然“做正确的事情”,但不鼓励省略 extern。这就是为什么较新版本的 Xcode 默认启用警告的原因。

【讨论】:

太棒了,谢谢你发布这个。我将一个项目导入到较新版本的 xcode 中,并看到此错误 - 赞! 我不知道为什么这没有早点出现。这在升级到 Xcode 8 时出现。 在升级 Xcode 后强制针对 iOS 8 时遇到此问题。 经过几个小时的工作,这终于解决了我遇到的问题......顺便说一句,放'extern'的原因是什么? 是的!在我的情况下,这是正确的答案。谢谢【参考方案4】:

这是 Xcode 7.0 中出现重复符号错误的情况,以防其他人遇到这种情况

.h file

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

@interface someViewController

//...

改成

.h file

@interface someViewController


   NSUserDefaults *defaults;


//...

【讨论】:

【参考方案5】:

当您在具有不同实现的不同文件中具有相同的@interface 时,也会发生这种情况。例如,您有一个 Player 类,在 Player.h/m 文件中,并且您有一个 Match 类 (Match.h/m),并且匹配是在两个玩家之间,但不是前面提到的 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

匹配.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

在这种情况下,编译器会看到两个不同的 Player 类实现。您需要将 Match.h 文件中的 Player 类重构为 MatchPlayer。

【讨论】:

【参考方案6】:

我遇到了一个问题,typedef 未添加到 enum 并且在 2 个文件之间出现重复符号错误。

enum <name> 
 ...
 <name>;

通过在enum 之前添加typedef 修复了重复符号。

【讨论】:

【参考方案7】:

在我的情况下,问题是 .m 文件被包含了两次。

问题:

原因:

解决方案:只保留一个文件引用。

【讨论】:

【参考方案8】:

如果这对其他人有帮助,那就是我的情况:

我想在 1 个头文件和实现文件中声明 2 个小类。

2 类正在使用 1 类

当我收到错误时,情况是这样的: 头文件 - 类 1 的接口+实现,类 2 的接口 实现文件 - 类 2 的实现

在我将类 1 的实现从头文件移动到实现文件后,没有错误,问题解决了: 头文件 - 类 1 的接口,类 2 的接口 实现文件——类1的实现,类2的实现

【讨论】:

【参考方案9】:

在我的例子中,我有相同的实体名称和 NSManagedObject 名称,并且未能在数据模型检查器中将实体类 Codegen 设置为“手动/无”。

【讨论】:

以上是关于Xcode 中架构的重复符号的主要内容,如果未能解决你的问题,请参考以下文章

Xcode 8.0 更新后架构 arm64 的重复符号

更新可可豆荚后xcode重复符号架构错误

架构 x86_64 Xcode 的 79 个重复符号

xcode ld:架构 x86_64 的 8 个重复符号

Firebase pod 为架构 arm64 生成重复符号

架构 armv7 的重复符号