从基本的测试程序...
package main
/*
#include <stdio.h>
static void test() {
printf("hello world");
}
*/
import "C"
func main() {
C.test();
}
Run Code Online (Sandbox Code Playgroud)
我做"cgo hello_cgo.go"并得到:
_cgo_.o
_cgo_defun.c
_cgo_gotypes.go
hello_cgo.cgo1.go
hello_cgo.cgo2.c
Run Code Online (Sandbox Code Playgroud)
我如何从这里编译到exe?
尝试使用go makefile.创建一个类似的makefile
# Makefile
CGOFILES=test.go
TARG=test
include $(GOROOT)/src/Make.$(GOARCH)
include $(GOROOT)/src/Make.pkg
Run Code Online (Sandbox Code Playgroud)
然后,运行make将生成文件_obj/test.a,您必须与之链接6l或相似.