我想从 Go 函数返回一个 C 结构值。假设ProcessX()和ProcessY()是返回整数(uint8 值)的 go 方法:
package main
/*
struct Point {
char x;
char y;
};
*/
import "C"
//export CreatePoint
func CreatePoint(x uint8, y uint8) C.Point {
xVal := ProcessX(x);
yVal := ProcessY(y);
return C.Point {x: xVal, y: yVal}
}
func main() {}
但这会导致构建错误:“ .\main.go:13:36: could not determine kind of name for C.Point”
编辑:
通过mingw在Windows 10中使用go build -ldflags "-s -w" -buildmode=c-shared -o mylibc.dll .\main.go编译
编辑2:
我已经删除了“C”导入和前面的序言之间的空行,但无法避免错误。现在的代码是这样的:
/*
struct Point {
char x;
char y;
};
*/
import "C"
茅侃侃
相关分类