Golang Cross-compiling

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

The local development environment is OS X server is Linux, so need to compile Linux go program, the method is as follows:
GOOS and Goarch reference for each platform

OS ARCH os Versionv

Linux 386/amd64/arm >= Linux 2.6

Darwin 386/amd64 OS X (Snow Leopard + Lion)

FreeBSD 386/amd64 >= FreeBSD 7

Windows 386/AMD64 >= Windows 2000

$ cd /usr/local/go/src$ sudo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash

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.

The execution results are similar to the following:

sudo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bashPassword:Building C bootstrap tool.cmd/distBuilding compilers and Go bootstrap tool for host, darwin/amd64.lib9libbiolibmachmisc/pprofcmd/addr2linecmd/covcmd/nmcmd/objdumpcmd/packcmd/profcmd/cc……pkg/text/template/parsepkg/text/templatepkg/go/docpkg/go/buildcmd/gopkg/runtime (linux/amd64)Building packages and commands for host, darwin/amd64.runtimeerrorssync/atomicunicodeunicode/utf8mathsyncunicode/utf16crypto/subtleiosyscall……….net/rpc/jsonrpctesting/iotesttesting/quickBuilding packages and commands for linux/amd64.runtimeerrorssync/atomicunicodeunicode/utf8mathsyncunicode/utf16……..testingnet/rpc/jsonrpctesting/iotesttesting/quickInstalled Go for linux/amd64 in /usr/local/goInstalled commands in /usr/local/go/bin

To the source code directory to execute:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build sina.go

Go build without the preceding parameters simply compiles the executable file that the development environment applies to.

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.