In my work, I write code on a Mac and deploy to work environments like Windows Server or Centos Linux.

So I needed to know how to build cross platform.  Running “go build” just built for my local machine.

I came across a video dealing with the subject:

In my case, I didn’t follow the entirety of his advice.  I had already installed XCode in the past, so I didn’t need to jump through those hoops.

All I needed was to run these params on the build command line, which set the OS and Architecture for the target device:

GOOS=linux GOARCH=amd64 go build portScanner.go

The above example sets the build process to make a binary for the Linux OS using the amd64 bit chipset.

I was able to do the same for Windows.  I’m not sure of all the values available.  I noticed I couldn’t specify intel64 or intel32 or x86 for Windows.  In my app, I was able to specify amd64 for Windows (even though it was an intel chipset) and the exe binary worked fine.



Comments are closed