开发者

Reachability ld: duplicate symbol _OBJC_IVAR_$_Reachability.localWiFiRef

开发者 https://www.devze.com 2023-03-16 17:28 出处:网络
I include \"Reachability/Reachability.m\" AppDelegate.h #import <UIKit/UIKit.h> #import \"Reachability/Reachability.m\"

I include "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;
}

and I get an error

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-iphonesimul开发者_StackOverflow中文版ator/.. .build/Objects-normal/i386/..AppDelegate.o

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

how to solve this problem? and what it might be related?


I was having the same problem because one third-party library (libPusher) I'm using was including Reachability already.

Since that library was pre-compiled, I wasn't sure what to do, but adding only Reachability.h to the project (and not Reachability.m) worked. That allowed me to import it and use the class but I didn't have the duplicate symbol issue.


You only import header files. Do,

#import "Reachability/Reachability.h"


you have to make sure your project folder contains one Reachability.h and one Reachability.m files , ASIHTTPRequest library has both these files in it hence the duplicate symbol error when adding the Reachability library. after removing the duplicate files do a clean build


  1. Removing the reference of reachability.m from the project.
  2. Add Framework or files you want (which created this issue).
  3. Clean and Build project

It worked for me.

when i tried adding framework in project, and this duplicate issue appeared.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号