2 回答
TA贡献1850条经验 获得超11个赞
新来这里。试图从 C 调用 go 函数但遇到了一些编译问题
这是 go 脚本
package main
// #cgo CFLAGS: -Wno-error=implicit-function-declaration
// #include <stdlib.h>
// #include "wrapper.c"
import "C"
//import "unsafe"
import "fmt"
//import "time"
//export dummy
func dummy() int {
fmt.Println("hi you");
return 0
}
func main() {
C.testc()
}
这是包装纸
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
extern int dummy();
void testc(){
dummy();
}
运行时报错
xyz@xyz-HP:~/learn/go$ go run reader.go
# command-line-arguments
In 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,
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,
from $WORK/command-line-arguments/_obj/_cgo_export.c:2:
./wrapper.c:6:12: note: previous declaration of ‘dummy’ was here
- 2 回答
- 0 关注
- 234 浏览
添加回答
举报