在我使用SIMBL连接的外部应用程序中,我遇到了一些很大的麻烦。
在这个应用程序中,有一个类-让我们称之为"AppClass“。在这个类中有一个函数,
-(void)doSomething;这是我从class中得到的--转储二进制文件。整个接口定义为:
@interface AppClass : NSObject
{
}我正在尝试用jr_swizzleMethod:withMethod:error覆盖这个函数:
在缺乏文档的情况下,我得出了以下结论:
#import "JRSwizzle.h"
#import "AppClass.h"
@interface AppClass (MyPlugin)
- (void)myPlugin_doSomething;
@end
@implementation AppClass (MyPlugin)
- (void)myPlugin_doSomething {
NSLog(@"lol?");
}
@end
@implementation MyPlugin
+ (void) load {
Mylugin* plugin = [MyPlugin sharedInstance];
NSError *err = nil;
BOOL result = [NSClassFromString(@"AppClass") jr_swizzleMethod:@selector(doSomething) withMethod:@selector(myPlugin_doSomething) error:&err];
if(!result)
NSLog(@"<Plugin> Could not install events filter (error: %@)", err);
NSLog(@"Plugin installed");
}
+ (MyPlugin *)sharedInstance {
static MyPlugin* plugin = nil;
if(plugin == nil)
plugin = [[MyPlugin alloc] init];
return plugin;
}
@end这应该足够了,对吧?但是我在编译时得到了这个错误:
Undefined symbols:
"_OBJC_CLASS_$_AppClass", referenced from:
l_OBJC_$_CATEGORY_AppClass_$_MyPlugin in MyPlugin.o
objc-class-ref-to-AppClass in MyPlugin.o
ld: symbol(s) not found
collect2: ld returned 1 exit status我该如何解决这个问题?
发布于 2010-11-14 17:46:45
您正在创建一个插件,它引用二进制文件中的符号(您试图扩展的应用程序)。因此,您需要告诉链接器在哪里查找这些符号(在您的示例中,这是_OBJC_CLASS_$_AppClass,即在二进制文件中定义的AppClass。)。
这是通过将选项-bundle_loader executable_name传递给链接器来完成的。参见the man page for ld。
https://stackoverflow.com/questions/4152907
复制相似问题