Golang 编译成DLL文件

  首先撰写golang程序exportgo.go:

package main
import "C"
import "fmt"

//export PrintBye

func PrintBye() {
    fmt.Println("From DLL: Bye!")
}
//export Sum

func 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两个文件。

 

参考:

https://www.yuque.com/docs/share/c82a9f4d-a289-433f-af5a-fcfa4d8082f5

你可能感兴趣的:(Go)