我正在嘗試使用 XPC、GCD 并繼續(xù)運(yùn)行,但是當(dāng)我的代碼無(wú)法編譯時(shí)出現(xiàn)以下錯(cuò)誤消息(我不明白),我很快就遇到了問(wèn)題:main(__DATA/__const): unexpected reloc for dynamic symbol _NSConcreteGlobalBlock main(__DATA/__const): unhandled relocation for _NSConcreteGlobalBlock (type 28 rtype 120)我正在使用go build以下代碼進(jìn)行編譯:main.gopackage main/*#include <xpc/xpc.h>#include "wrapper.h"*/import "C"import ( "fmt")//export HandleXPCEventfunc HandleXPCEvent(event C.xpc_object_t) { fmt.Println("Event was handled")}func main() { name := C.CString("com.example.xpc") queue := C.dispatch_queue_create(name, nil) conn := C.xpc_connection_create(name, queue) C.set_event_handler(conn) //C.xpc_connection_resume(conn)}包裝器.h#ifndef _WRAPPER_H_#define _WRAPPER_H_#include <stdlib.h>#include <stdio.h>#include <xpc/xpc.h>xpc_connection_t connect( char* name);void set_event_handler(xpc_connection_t connection);#endif包裝器#include "wrapper.h"#include <dispatch/dispatch.h>extern void HandleXPCEvent(xpc_object_t);xpc_connection_t connect( char* name) { dispatch_queue_t queue = dispatch_queue_create(name,0); return xpc_connection_create(name,queue);}void set_event_handler(xpc_connection_t connection) { xpc_connection_set_event_handler(connection, ^(xpc_object_t event) { xpc_retain(event); // Call Go function HandleXPCEvent(event); });}我是不是做錯(cuò)了什么?這是某種 go 錯(cuò)誤還是如何修復(fù)?
使用 cgo 包裝 <dispatch/dispatch.h> 時(shí)構(gòu)建錯(cuò)誤
達(dá)令說(shuō)
2021-06-17 22:21:06