0

I read this and this about this activity, and the action mentioned as:

% env GOOS=darwin GOARCH=386 go build hello.go

// or

% env GOOS=linux GOARCH=arm GOARM=7 go build hello.go

// and so on

But in Windows there is no command named env, I got the below:

'env' is not recognized as an internal or external command,
operable program or batch file.
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203

2 Answers2

1

On windows powershell you should be able to do:

$env:GOOS = "linux"
$env:GOARCH = "arm"
$env:GOARM = "7"
go build hello.go
dave
  • 62,300
  • 5
  • 72
  • 93
0

To check supported compilation tools: go tool dist list Cross compiling not working with cgo, i.e. not working with any file has import "C"

At Powershell

# For ARM
$env:GOOS = "linux" 
$env:GOARCH = "arm" 
$env:GOARM = "7" 
go build -o main main.go
# For darwin
$env:GOOS = "darwin" 
$env:GOARCH = "amd64" 
go build -o main.dmg main.go
# same for others
$env:GOOS = "windows" 
$env:GOARCH = "amd64" 
go build -o main.exe main.go

At CMD Command Prompt:

set GOOS=darwin
set GOARCH=amd64
go build -o main.dmg main.go

To do it in Linux or Mac and compiling to Win

GOOS=windows GOARCH=amd64 go build -o main.exe main.go

Cross compiling will silently rebuild most of standard library, and for this reason will be quite slow. To speed-up the process, you can install all the standard packages required for cross compiling on your system, for example to install at Linux/Mac the cross compiling requirements for windows-amd64 use:

GOOS=windows GOARCH=amd64 go install

Similar for any other OS you need to cross compile for it at Windows

Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203