可达性ld:重复符号_OBJC_IVAR _ $ _ Reachability.localWiFiRef

时间:2011-06-29 12:37:27

标签: objective-c duplicates symbols reachability

我包括“Reachability / Reachability.m”

AppDelegate.h

#import <UIKit/UIKit.h>
#import "Reachability/Reachability.m"

@class ...;

@interface ... : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    ... *viewController;
    Reachability *hostReach;
    NetworkStatus netStatus;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic) NetworkStatus netStatus;
-(void)updateInterfaceWithReachability: (Reachability*) curReach;

@end


AppDelegate.m


#import "AppDelegate.h"
#import "ViewController.h"

@implementation ...

@synthesize window=_window;
@synthesize navigationController=_navigationController;
@synthesize netStatus;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
    hostReach = [[Reachability reachabilityWithHostName:@"www.apple.com"]retain];
    [hostReach startNotifier];
    [self updateInterfaceWithReachability:hostReach];


    // Set the view controller as the window's root view controller and display.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

我收到错误

ld: duplicate symbol _OBJC_IVAR_$_Reachability.localWiFiRef in /Users/../Documents/../build/.. .build/Debug-iphonesimulator/.. .build/Objects-normal/i386/..ViewController.o and /Users/../Documents/../build/.. .build/Debug-iphonesimulator/.. .build/Objects-normal/i386/..AppDelegate.o

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

如何解决这个问题?和它可能有什么关系?

3 个答案:

答案 0 :(得分:5)

我遇到了同样的问题,因为我使用的一个第三方库(libPusher)已经包含了Reachability。

由于该库是预编译的,我不知道该怎么做,但只在项目中添加Reachability.h(而不是Reachability.m)。这允许我导入它并使用该类,但我没有重复的符号问题。

答案 1 :(得分:2)

您只导入头文件。做,

#import "Reachability/Reachability.h"

答案 2 :(得分:2)

您必须确保您的项目文件夹包含一个Reachability.h和一个Reachability.m文件,ASIHTTPRequest库中包含这两个文件,因此在添加Reachability库时出现重复的符号错误。删除重复文件后执行干净构建