可达性 ld:重复符号 _OBJC_IVAR_$_Reachability.localWiFiRef

发布于 2024-11-18 05:01:03 字数 1952 浏览 2 评论 0原文

我包含“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

如何解决此问题?它可能与什么有关?

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-iphonesimulator/.. .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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

终弃我 2024-11-25 05:01:03

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

由于该库是预编译的,我不确定该怎么做,但仅将 Reachability.h 添加到项目中(而不是 Reachability.m)就可以了。这允许我导入它并使用该类,但我没有遇到重复符号问题。

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.

农村范ル 2024-11-25 05:01:03

您只导入头文件。做,

#import "Reachability/Reachability.h"

You only import header files. Do,

#import "Reachability/Reachability.h"
清风疏影 2024-11-25 05:01:03

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

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

几度春秋 2024-11-25 05:01:03
  1. 从项目中删除对reachability.m的引用。
  2. 添加所需的框架或文件(导致此问题的原因)。
  3. 清理和构建项目

它对我有用。

当我尝试在项目中添加框架时,出现了这个重复的问题。

  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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文