Cross-platform compilation Go Program (Cross compilation)

Source: Internet
Author: User
Tags install go

Role: For example, you have a Mac system on hand, and your users have Linux and Windows, and they want to use it, you can cross-compile the executable files on Linux and Windows to give them

(1) First enter the GO/SRC source directory, execute the following command to create the target platform required package and tool files.

$ cd/usr/local/go/src$ cgo_enabled=0 goos=linux goarch=amd64./make.bash

If it is Windows, you can modify GOOS.

$ cgo_enabled=0 goos=windows goarch=amd64./make.bash

(2) The executable files required for Linux and Windows platforms can now be compiled.

$ cgo_enabled=0 goos=linux goarch=amd64 go build$ cgo_enabled=0 goos=windows goarch=amd64 Go Build

However, this approach does not support CGO for the time being.

http://solovyov.net/en/2012/03/09/cross-compiling-go/

The above assumptions are 64-bit architecture, 32-bit, modified Goarch to 386

Description
This is not to recompile go, because when you install go, you just compile what your local system needs, and cross-platform compilation requires more support for other platforms in go. So, there is./make.bash such a process

Cross-compilation issues supplement:

First, it is recommended to install the go language through the source installation, otherwise there may be no make.bash or Make.bat program.

The above steps need to be performed because some of the tools and platform-related code is not generated when you install the Go language, and instead of reinstalling the go language, you will build the tools and files needed for cross-compilation (target platform). These are only done at the time of the first cross-compilation. After that, you don't need it.

For faster compilation, you can

./make.bash--no-clean

Transferred from: HTTP://STUDYGOLANG.COM/TOPICS/21

Cross-platform compilation Go Program (Cross compilation)

Related Article

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.