Skip to content

Instantly share code, notes, and snippets.

@copyleftdev
Created November 2, 2016 14:50
Show Gist options
  • Save copyleftdev/fa785e7439783b78dbb5d26a0e38a60b to your computer and use it in GitHub Desktop.
Save copyleftdev/fa785e7439783b78dbb5d26a0e38a60b to your computer and use it in GitHub Desktop.
cross compile

Code Sample

package main

import "fmt"
import "runtime"

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

Now build for darwin/386

z% 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

Or build for Windows

 GOOS=windows GOARCH=386 go build -o hello.exe hello.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment