iOS的重复符号链接错误

时间:2015-02-09 15:38:21

标签: ios objective-c xcode

我是iOS开发领域的新手,但我之前做过一些有限的C和C ++编程,这让我相信我的Objective-C代码是正确的,即使Xcode给了我以下链接器错误:

Ld /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Products/Debug-iphoneos/objc-vvc.app/objc-vvc normal armv7
    cd /Users/nillerr/Documents/xcode/objc-vvc
    export IPHONEOS_DEPLOYMENT_TARGET=8.1
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.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 armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -L/Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Products/Debug-iphoneos -F/Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Products/Debug-iphoneos -filelist /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/objc-vvc.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -fobjc-arc -fobjc-link-runtime -miphoneos-version-min=8.1 -Xlinker -dependency_info -Xlinker /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/objc-vvc_dependency_info.dat -o /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Products/Debug-iphoneos/objc-vvc.app/objc-vvc

duplicate symbol _OBJC_IVAR_$_VidyoOutEvent._event in:
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/AppVidyoClient.o
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/LoginViewController.o
duplicate symbol _OBJC_IVAR_$_VidyoOutEvent._param in:
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/AppVidyoClient.o
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/LoginViewController.o
duplicate symbol _OBJC_IVAR_$_VidyoOutEvent._paramSize in:
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/AppVidyoClient.o
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/LoginViewController.o
duplicate symbol _OBJC_IVAR_$_VidyoOutEvent._data in:
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/AppVidyoClient.o
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/LoginViewController.o
duplicate symbol _OBJC_METACLASS_$_VidyoOutEvent in:
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/AppVidyoClient.o
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/LoginViewController.o
duplicate symbol _OBJC_CLASS_$_VidyoOutEvent in:
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/AppVidyoClient.o
    /Users/nillerr/Library/Developer/Xcode/DerivedData/objc-vvc-bnuejnodyndpcggqtwhovkyuuivi/Build/Intermediates/objc-vvc.build/Debug-iphoneos/objc-vvc.build/Objects-normal/armv7/LoginViewController.o
ld: 6 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我已经搜索并尝试过多种解决方案,包括编辑项目文件,检查重复项或.h文件的构建阶段,但到目前为止还没有任何工作。我该如何解决这个问题?

我已经附加了相关文件的代码:

AppVidyoClient.h

#ifndef vvc_AppVidyoClient_h
#define vvc_AppVidyoClient_h

#import "VidyoClient.h"

@interface AppVidyoClient : NSObject <VidyoClient>
{

}

+ (AppVidyoClient*) instance;

@end

#endif

AppVidyoClient.m

#import <Foundation/Foundation.h>
#import "AppVidyoClient.h"
#import "NSURLConnection+Blocks.h"
#import "Tolo.h"
#import "Messages.h"

static AppVidyoClient *instance;

@interface AppVidyoClient ()
{

}

@end

@implementation AppVidyoClient
#pragma mark Class methods
+ (AppVidyoClient *) instance
{
    if (!instance) {
        instance = [[AppVidyoClient alloc] init];
    }
    return instance;
}

#pragma mark init / dealloc
- (id) init
{
    if (self = [super init]) {

    }

    return self;
}

- (void) login:(NSString *)portal username:(NSString *)username password:(NSString *)password
{
    NSDictionary *params = @{
                             @"portal": portal,
                             @"username": username,
                             @"password": password
                             };

    [self post:@"login" parameters:params];
}

- (void) post:(NSString *)action parameters:(NSDictionary *)parameters
{
    NSString *url = [NSString stringWithFormat:@"http://webadmin.lifeline.viewcare.com/ios.php?do=%@", action];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"text/json" forKey:@"Content-Type"];

    NSError *error;
    NSData *body = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];

    [request setHTTPBody:body];

    NSString *strLength = [NSString stringWithFormat:@"%lu", (unsigned long)[body length]];
    [request setValue:strLength forKey:@"Content-Length"];

    [NSURLConnection asyncRequest:request success:^(NSData *data, NSURLResponse *response) {
        [self onSuccess:data response:response];
    } failure:^(NSData *data, NSError *error) {
        [self onFailure:data error:error];
    }];
}

- (void) onSuccess:(NSData *)data response:(NSURLResponse *)response
{
    NSError *error;
    NSDictionary *resp = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

    VidyoOutEvent *event = [[VidyoOutEvent alloc] init];
    event.event = (VidyoClientOutEvent) [resp valueForKey:@"event"];
    event.param = (__bridge VidyoVoidPtr)([resp valueForKey:@"param"]);
    event.paramSize = (int) [resp valueForKey:@"paramSize"];
    event.data = (__bridge VidyoVoidPtr)([resp valueForKey:@"data"]);

    PUBLISH(event);
}

- (void) onFailure:(NSData *)data error:(NSError *)error
{

}

@end

LoginViewController.h

#ifndef vvc_LoginViewController_h
#define vvc_LoginViewController_h

#import <UIKit/UIKit.h>

@interface LoginViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *mTxtServer;

- (IBAction)onSignInClick:(UIButton *)sender;

@end

#endif

LoginViewController.m

#import <UIKit/UIKit.h>
#import "Tolo.h"
#import "LoginViewController.h"
#import "VidyoClient.h"
#import "AppVidyoClient.h"
#import "AppDelegate.h"
#import "Messages.h"

#define SUBSCRIBE_TO(_event_id_) - (void) onVidyoOutEvent:(VidyoOutEvent *) event data:(VidyoClientOutEvent) data

@interface LoginViewController ()
{
    // Private members
    int mPrivateInt;
}

@property (readwrite, nonatomic) id <VidyoClient> client;
@end

@implementation LoginViewController
#pragma mark Class Methods

#pragma mark Init & Dealloc methods
- (id) init
{
    if (self = [super init]) {

    }

    return self;
}

#pragma mark ViewController
- (void) viewDidLoad
{
    [super viewDidLoad];
    _client = AppVidyoClient.instance;

    // Register on EventBus
    REGISTER();
}

#pragma mark EventBus handlers
SUBSCRIBE(VidyoOutEvent)
{
    switch (event.event) {
        case VIDYO_CLIENT_OUT_EVENT_SIGNED_IN:
        {
            NSString *param = event.param;
            if ([param isEqualToString:@"OK"]) {
                // Move to signed in view
                [self performSegueWithIdentifier:@"signInComplete" sender:self];
            }
            break;
        }
    }
}

#pragma mark Instance methods
- (IBAction)onSignInClick:(UIButton *)sender {
    NSString *portal = _mTxtServer.text;
    [_client login:portal username:@"" password:@""];
}

@end

Messages.h

#ifndef objc_vvc_Messages_h
#define objc_vvc_Messages_h

typedef enum VidyoClientOutEvent_
{
    VIDYO_CLIENT_OUT_EVENT_SIGNED_IN = 2303,
} VidyoClientOutEvent;

typedef void *VidyoVoidPtr;
typedef unsigned int VidyoUint;

@interface VidyoOutEvent : NSObject

@property VidyoClientOutEvent event;
@property VidyoVoidPtr param;
@property VidyoUint paramSize;
@property VidyoVoidPtr data;

@end

@implementation VidyoOutEvent

@end

#endif

1 个答案:

答案 0 :(得分:1)

我一定被Objective-C的新语法所蒙蔽......解决方案很简单:

移动

@implementation VidyoOutEvent

@end

出于 Messages.h 并进入实施文件 Messages.m

#import "Messages.h"

@interface VidyoOutEvent ()
{

}
@end

@implementation VidyoOutEvent

@end