Golang is cross-compiled under various platforms

藏色散人
Release: 2021-02-02 15:50:41
forward
2392 people have browsed it

The following column will introduce you to Golang cross-compilation under various platforms from the golang tutorial column. I hope it will be helpful to friends in need!

Golang is cross-compiled under various platforms

#Golang supports cross-compilation, which can generate an executable program for another platform on one platform. I have used it recently and it is very easy to use. Here is a note.

Parameter description

  • GOOS: The operating system of the target platform (darwin, freebsd, linux, windows)
  • GOARCH: The architecture of the target platform (386, amd64, arm)
  • CGO_ENABLED: Cross compilation does not support CGO so disable it

Compile Linux and Windows 64-bit executable programs under Mac

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
Copy after login

Compile Mac and Windows 64-bit executable programs under Linux

CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
Copy after login

Compile Mac and Linux 64-bit executable programs under Windows

SET CGO_ENABLED=0
SET GOOS=darwin
SET GOARCH=amd64
go build main.go

SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build main.go
Copy after login

The above command compiles a 64-bit executable program. Of course you should also use 386 to compile a 32-bit executable program        

More golang related technologies For articles, please visit the go language column!                                                                    

The above is the detailed content of Golang is cross-compiled under various platforms. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
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