Golang compile for all platforms in Windows 7 (32 bit)

Issue

I’m using windows 7 [32 bit] operating system.

I’m build example go program.

I want to compile this program for all platforms from my windows 7 [32 bit] OS.

I want to compile my program for all Linux [32/64] / Mac OSX [32/64] / Windows[32/64].

Is it possible are not from my single OS ?

Solution

Update Go 1.5: see “Cross compilation just got a whole lot better in Go 1.5

For successful cross compilation you would need

  • compilers for the target platform, if they differed from your host platform, ie you’re on darwin/amd64 (6g) and you want to compile for linux/arm (5g).
  • a standard library for the target platform, which included some files generated at the point your Go distribution was built.

With the plan to translate the Go compiler into Go coming to fruition in the 1.5 release the first issue is now resolved.

package main

import "fmt"
import "runtime"

func main() {
        fmt.Printf("Hello %s/%s\n", runtime.GOOS, runtime.GOARCH)
}

build for darwin/386

% env GOOS=darwin GOARCH=386 go build hello.go
# scp to darwin host
$ ./hello
Hello darwin/386

Or build for linux/arm

% env GOOS=linux GOARCH=arm GOARM=7 go build hello.go
# scp to linux host
$ ./hello
Hello linux/arm

Original answer (Go 1.4 and before)

You can try a tool like gox

Gox is a simple, no-frills tool for Go cross compilation that behaves a lot like standard go build.
Gox will parallelize builds for multiple platforms.
Gox will also build the cross-compilation toolchain for you.

Before you use Gox, you must build the cross-compilation toolchain. Gox can do this for you. This only has to be done once (or whenever you update Go):

$ gox -build-toolchain

You will also find many cross-platform development tips at “Developing for Multiple Platforms With Go“.

Passionate Developer points out below to issue 19, left by the OP Nakka Chandra, even though issue 10 reported making gox run successfully on Windows.

Answered By – VonC

Answer Checked By – Pedro (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.