我正在尝试为 lirc 进行 Go 绑定:https : //github.com/inando/go-lirc
lirc_init() 和 lirc_deinit() 之类的简单函数可以正常工作。
对于函数“lirc_command_init()”,我需要使用结构类型:https : //github.com/inando/lirc/blob/master/lib/lirc_client.h#L334
typedef struct {
char packet[PACKET_SIZE + 1];
char buffer[PACKET_SIZE + 1];
char reply[PACKET_SIZE + 1];
int head;
int reply_to_stdout;
char* next;
} lirc_cmd_ctx;
Run Code Online (Sandbox Code Playgroud)
我首先尝试了这样的事情:
func lircCommandInit(format string, v ...interface{}) (todoctx string, err error) {
var ctx C.struct_lirc_cmd_ctx
cmd := C.CString(fmt.Sprintf(format, v...))
ok, err := C.lirc_command_init(ctx, cmd)
fmt.Println(ok, err)
return
}
Run Code Online (Sandbox Code Playgroud)
但这给了我这个错误:无法确定 C.lirc_command_init 的名称类型。
不确定 struct_ 是否应该用于类型?
ctx 可能需要是一个指针,但我总是得到同样的错误。
然后我尝试使用包装器,但这给了我错误未知类型名称“lirc_cmd_ctx”
// #cgo LDFLAGS: -llirc_client
// #cgo CFLAGS: -I /usr/include/lirc
// #include <lirc_client.h>
//
// int lirc_command_init_custom(const char* msg)
// {
// lirc_cmd_ctx ctx;
// return -2;
// }
import "C"
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?如何在 Go 中使用该结构类型?
更新:
不确定这是否相关,但 C.free 也抱怨。
p := C.CString(prog)
defer C.free(unsafe.Pointer(p))
Run Code Online (Sandbox Code Playgroud)
-> 无法确定 C.free 的名称类型
Go 版本:go 版本 go1.4 linux/amd64(Windows 上的 Vagrant)
该could not determine kind of name for ...消息是您在未定义某些内容时得到的信息。在 的情况下C.free,添加stdlib.h到您的包含中。
#include <stdlib.h>
Run Code Online (Sandbox Code Playgroud)
其他错误也是如此,除了这是导入不正确的标头或该标头的不正确版本的情况。检查随机 ubuntu 系统,该lirc_client.h文件与您链接的文件大不相同。确保您使用的是定义类型的正确版本。
| 归档时间: |
|
| 查看次数: |
1789 次 |
| 最近记录: |