Can Golang be packaged as a dll?
1. Download and install MinGW, a set of MinGW integrated compilers;
The full name of MinGW is Minimalist GNU For Windows. It is a streamlined Windows platform C/C, ADA and Fortran compiler
Win 64-bit version of MinGW: https://sourceforge.net/projects/ mingw-w64/
2. Run the MinGW installation program and complete the installation;
After downloading, runmingw-w64-install.exe
3. Write a Golang program;
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 }
4. Use the "go build" command to compile the program into a dll file.
go build -buildmode=c-shared -o exportgo.dll exportgo.go
After compilation, we get two files exportgo.dll
and exportgo.h
.
Recommended tutorial: "Go Tutorial"
The above is the detailed content of Can Golang be packaged as dll?. For more information, please follow other related articles on the PHP Chinese website!