Tutorial by Examples

This Makefile will cross compile and zip up executables for Windows, Mac and Linux (ARM and x86). # Replace demo with your desired executable name appname := demo sources := $(wildcard *.go) build = GOOS=$(1) GOARCH=$(2) go build -o build/$(appname)$(3) tar = cd build && tar -cvzf $...
From your project directory, run the go build command and specify the operating system and architecture target with the GOOS and GOARCH environment variables: Compiling for Mac (64-bit): GOOS=darwin GOARCH=amd64 go build Compiling for Windows x86 processor: GOOS=windows GOARCH=386 go build ...
Another convenient solution for cross compilation is the usage of gox: https://github.com/mitchellh/gox Installation The installation is done very easily by executing go get github.com/mitchellh/gox. The resulting executable gets placed at Go's binary directory, e.g. /golang/bin or ~/golang/bin. E...
Prepare helloworld.go (find below) package main import "fmt" func main(){ fmt.Println("hello world") } Run GOOS=linux GOARCH=arm go build helloworld.go Copy generated helloworld (arm executable) file to your target machine.

Page 1 of 1