可达性 ld:重复符号 _OBJC_IVAR_$_Reachability.localWiFiRef
我包含“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题,因为我正在使用的一个第三方库(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 notReachability.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,
您必须确保您的项目文件夹包含一个 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
它对我有用。
当我尝试在项目中添加框架时,出现了这个重复的问题。
It worked for me.
when i tried adding framework in project, and this duplicate issue appeared.