golang C相互调用带参数
test.h
#ifndef __TEST_H__ #define __TEST_H__ void SetFunc(char* str); extern void InternalFunc(char* str); #endif
test.c
#include "test.h" void SetFunc(char* str) { InternalFunc(str); }
test.go
package main // #include "test.h" import "C" import "fmt" var function func(str *C.char) //export InternalFunc func InternalFunc(str *C.char) { function(str) } func Register(fnct func(str *C.char)) { function = fnct cs := C.CString("aaaaaaaaaaa") C.SetFunc(cs) } func test(str *C.char) { fmt.Println("How should I do it", C.GoString(str)) } func main() { Register(test) }