从c调用go函数时出错

POPMUISE
浏览 235回答 2
2回答

慕盖茨4494581

新来这里。试图从 C 调用 go 函数但遇到了一些编译问题这是 go 脚本package main// #cgo CFLAGS: -Wno-error=implicit-function-declaration// #include <stdlib.h>&nbsp;// #include "wrapper.c"import "C"//import "unsafe"import "fmt"//import "time"//export dummyfunc dummy() int {&nbsp; &nbsp; fmt.Println("hi you");&nbsp; &nbsp; return 0}func main() {&nbsp; &nbsp; C.testc()}这是包装纸#include <sys/types.h>#include <stdio.h>#include <errno.h>#include <string.h>extern int dummy();void testc(){&nbsp; &nbsp; dummy();}运行时报错xyz@xyz-HP:~/learn/go$ go run reader.go&nbsp;# command-line-argumentsIn file included from $WORK/command-line-arguments/_obj/_cgo_export.c:2:0:reader.go:30:14: error: conflicting types for ‘dummy’In file included from reader.go:3:0,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from $WORK/command-line-arguments/_obj/_cgo_export.c:2:./wrapper.c:6:12: note: previous declaration of ‘dummy’ was here/tmp/go-build528677551/command-line-arguments/_obj/_cgo_export.c:8:7: error: conflicting types for ‘dummy’In file included from reader.go:3:0,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from $WORK/command-line-arguments/_obj/_cgo_export.c:2:./wrapper.c:6:12: note: previous declaration of ‘dummy’ was here
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go