cgeventtap的apple mach-o链接器id错误

时间:2011-11-10 03:30:56

标签: macos cocoa

我正在尝试使CGEventTap工作。我想我已经完成了所有事情但是当我去跑步时我得到了这个错误:

Apple Mach-O Linker (id) Error

Undefined symbols for architecture x86_64:
  "_tapCallback", referenced from:
      -[TestAppDelegate applicationDidFinishLaunching:] in TestAppDelegate.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

1 个答案:

答案 0 :(得分:2)

听起来您已经定义了tapCallback()功能,但实际上还没有实现它。换句话说,您的TestAppDelegate类可能看起来像这样:

#import "TestAppDelegate.h"

CGEventRef tapCallback(CGEventTapProxy proxy,
            CGEventType type,
           CGEventRef event,
              void *userInfo);


@implementation TestAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    CFMachPortRef eventTapRef = CGEventTapCreate(kCGSessionEventTap, 
                                                 kCGTailAppendEventTap,
                                                 kCGEventTapOptionListenOnly,
                                                 kCGEventMaskForAllEvents,
                                                 tapCallback,
                                                 NULL);
    // additional code

}

@end

在某些地方,你需要实际实现tapCallback()功能。如果您实际已经在另一个文件中实现了它,请确保该文件包含在您构建的目标中。

否则,执行此类操作应允许程序运行:

CGEventRef tapCallback(CGEventTapProxy proxy,
                             CGEventType type,
                                CGEventRef event,
                                   void *userInfo) {
    NSLog(@"tapCallback()");
    return event;
}