1

当我尝试编译以下代码时,有谁知道为什么会出现链接器错误:

extern void * _CTServerConnectionCreate(CFAllocatorRef, int (*)(void *, CFStringRef, CFDictionaryRef, void *), int *);

int callback(void *connection, CFStringRef string, CFDictionaryRef dictionary, void *data) 
{
    return 0;
}

%hook UIKeyboard

-(id)hitTest:(CGPoint)test withEvent:(id)event
{
    int x = 0;
    _CTServerConnectionCreate(kCFAllocatorDefault, callback, &x);
    return %orig;
}

%end

使输出为:

架构 armv6 的未定义符号:“ CTServerConnectionCreate( _CFAllocator const*, int ( )(void , __CFString const*, __CFDictionary const*, void*), int*)”,引用自:$_ungrouped$UIKeyboard$hitTest$withEvent$(UIKeyboard *, objc_selector*, CGPoint, objc_object*) 在 Tweak.xm.o ld: 未找到架构 armv6 collect2 的符号: ld 返回 1 个退出状态

一些注意事项:

  • 我使用-framework CoreTelephony 链接 CoreTelephony
  • 我使用这里的代码Core Telephony Example
  • 我在 iOS 4.x 和 iOS 5.x 上都试过了
  • 我使用nm来确保函数调用在二进制文件中

是的,我在越狱设备上。

谢谢 ;)

4

2 回答 2

0

只需在 XCode 中包含 CoreTelephony.framework。应该管用!

于 2012-01-14T20:33:22.963 回答
0

您可能希望在不带下划线的情况下声明您的私有函数。

 extern void *CTServerConnectionCreate();

// Call
myRes = CTServerConnectionCreate(args);

编译器会自动添加下划线前缀。

于 2012-01-14T21:22:19.917 回答