Home > Backend Development > Golang > Can Golang be packaged as dll?

Can Golang be packaged as dll?

Guanhui
Release: 2020-06-10 11:27:32
Original
3531 people have browsed it

Can Golang be packaged as dll?

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  
}
Copy after login

4. Use the "go build" command to compile the program into a dll file.

go build -buildmode=c-shared -o exportgo.dll exportgo.go
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template