我想从 C 函数空间调用 go func,但程序抛出构建错误。例子.gopackage main/*#include "test.c"*/import "C"import "fmt"func Example() { fmt.Println("this is go") fmt.Println(C.GoString(C.myprint(C.CString("go!!"))))}// export receiveC (remove the extra space between // and export)func receiveC(msg *C.char) { fmt.Println(C.GoString(msg))}func main() { Example()}测试.c#include <stdio.h>extern void receiveC(char *msg);char* myprint(char *msg) { receiveC(msg); // calling the exported go function return msg; }当我执行命令来运行/构建(go build或go run example.go或go build example.go)程序时,它会抛出错误:# github.com/subh007/goodl/cgoUndefined symbols for architecture x86_64: "_receiveC", referenced from: _myprint in example.cgo2.o __cgo_6037ec60b2ba_Cfunc_myprint in example.cgo2.o _myprint in test.old: symbol(s) not found for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to see invocation)我正在按照cgo 幻灯片编写程序。请让我知道这里的任何错误。编辑 1:我使用的是 OS-X 10.9 操作系统。EDIT2:我之间的一个额外的空间// export,应该有之间没有空格//和export。但是现在我在构建时遇到以下错误:# github.com/subh007/goodl/cgoduplicate symbol _myprint in: $WORK/github.com/subh007/goodl/cgo/_obj/_cgo_export.o $WORK/github.com/subh007/goodl/cgo/_obj/example.cgo2.oduplicate symbol _receiver_go in: $WORK/github.com/subh007/goodl/cgo/_obj/_cgo_export.o $WORK/github.com/subh007/goodl/cgo/_obj/example.cgo2.oduplicate symbol _myprint in: $WORK/github.com/subh007/goodl/cgo/_obj/_cgo_export.o $WORK/github.com/subh007/goodl/cgo/_obj/test.oduplicate symbol _receiver_go in: $WORK/github.com/subh007/goodl/cgo/_obj/_cgo_export.o $WORK/github.com/subh007/goodl/cgo/_obj/test.old: 4 duplicate symbols for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to see invocation)
1 回答
- 1 回答
- 0 关注
- 175 浏览
添加回答
举报
0/150
提交
取消