Golang cross-compiling on Mac, Linux, Windows

Source: Internet
Author: User

Golang supports the ability to generate cross-compilation of another platform executable program under one platform.

Linux under Mac, 64-bit executable program for Windows platform:

1 cgo_enabled=0 goos=linux goarch=amd64 go build [Application | gofile.go]2 cgo_ enabled=0 goos=windows goarch=amd64 go build [Application | gofile.go]

Linux under Compile Mac, Windows platform 64-bit executable:

1 cgo_enabled=0 goos=darwin goarch=amd64 go build [Application | gofile.go]2 cgo_ enabled=0 goos=windows goarch=amd64 go build [Application | gofile.go]

Windows compiles 64-bit executables for Mac, Linux platforms:

1 Set cgo_enabled=02 set goos=Darwin3 set goarch=amd644 go build [Application | gofile.go]56 set cgo_enabled=07 Set GOOS =Linux8 SET goarch=amd649 Go build [Application | gofile.go]

GOOS: The target executable program runs the operating system and supports Darwin,freebsd,linux,windows
Goarch: Target executable program operating system architecture, including 386,amd64,arm

Golang version 1.5 The cross-compilation environment also needs to be configured during the first cross-compilation:

1 cgo_enabled=0 goos=linux goarch=amd64./make. Bash2 cgo_enabled=0 goos=windows goarch=amd64./make. Bash

Make.bash files are only used when the Golang source code is compiled and installed.

Golang cross-compiling on Mac, Linux, Windows

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.