Golang Cross-compiling

Source: Internet
Author: User
  1. Go ENV Check the environment variables are correct
  2. Enter the shell environment (Windows is a CMD environment) and switch to the project source directory (the directory containing the main package)
  3. Set the environment variables, close the CGO (cross-compilation does not support so to close), set the environment variables to compile the target platform, and then execute the Go Build command, the method is as follows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build

The bash shell environment can be used as above, and if it is a Windows CMD environment, set with the SET command

cgo_enabled Close Cgo,goos Set Target operating system, Goarch set Target schema

Can be combined with the following

$GOOS        $GOARCHandroid     armdarwin      386darwin      amd64darwin      armdarwin      arm64dragonfly   amd64freebsd     386freebsd     amd64freebsd     armlinux       386linux       amd64linux       armlinux       arm64linux       ppc64linux       ppc64lelinux       mipslinux       mipslelinux       mips64linux       mips64lenetbsd      386netbsd      amd64netbsd      armopenbsd     386openbsd     amd64openbsd     armplan9       386plan9       amd64solaris     amd64windows     386windows     amd64

Set the environment variable and then execute the Go Build command to compile the executable file on the target platform.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.