Golang cross-compiling Linux programs under Windows

Source: Internet
Author: User
Tags install go
This is a creation in Article, where the information may have evolved or changed.

1, download the relevant procedures.

Golang Download: http://www.golangtc.com/download

git download: http://git-scm.com/download/

TDM-GCC Download: http://tdm-gcc.tdragon.net/download

2, go to compile the environment configuration

Install TDM-GCC, the program will automatically set the PATH environment variable, if not set successfully please manually set.

Install go, you need to set the GOROOT,GOPATH,GOBIN,PATH environment variable after installation,

which

Goroot for your go installation and directory

Gopath for your Go Program development directory, the go get after the package will also be downloaded to the directory.

Gobin for your Go run directory, after running the Go Install command, the program will be installed into the directory.

Path is the root of your go program and is used to invoke the GO command from the console.

3. Configuring the Cross-compilation environment

In the Go root directory of the SRC directory, create a new BUILD.bat file, and copy the contents as follows:

Set cgo_enabled=0Set Goroot_bootstrap=c:/go::x86 block Set Goarch=386Set GOOS=Windowscall Make. bat--no-Clean set GOOS=Linuxcall Make. bat--no-Clean set GOOS=Freebsdcall Make. bat--no-Clean set GOOS=Darwincall Make. bat--no-On the x64:::::::::::.::: : ,:-:::-------:------:----:::----::: £:::::,:-:::;=Amd64set GOOS=Linuxcall Make. bat--no-For:::::::::::::::::--:::----:::---:::---:::---:::---:::---:::: goarch=Armset GOOS=Linuxcall Make. bat--no-In:::::::::::::::::-::::-::--:::-: goarch: :::::.::----:.::-=386Set GOOS=Windowsgo Get github.com/nsf/Gocodepause

My Go program version is 1.6, you need to set the Goroot_bootstrap variable to go installation directory, otherwise the execution will be error.

Then run BUILD.bat and wait for the end.

The program compiles other platforms to compile the libraries and compile files required by go.

When you are finished, follow the cmd command line in turn:

Set Goos=linux

Set GOPACH=AMD64

Go build-o-x APPNAME main.go

The compiled file will appear in the corresponding directory in Main.go.

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.