我想從 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 回答
- 0 關注
- 191 瀏覽
添加回答
舉報
0/150
提交
取消