首先撰写golang程序exportgo.go:
package mainimport "C"import "fmt"//export PrintByefunc PrintBye() {fmt.Println("From DLL: Bye!")}//export Sumfunc Sum(a int, b int) int {return a + b;}func main() {// Need a main function to make CGO compile package as C shared library}
编译成 DLL 文件:
go build -buildmode=c-shared -o exportgo.dll exportgo.go
编译后得到 exportgo.dll 和 exportgo.h两个文件。

