Golang – Cross Platform Building

Compiling for Windows, Linux and OSX

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.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Admin

I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It's my hope that it gives hope to any and all who are self-taught.

Go – GoRoutines, Channels and Threads

Dirgo – Directory Brute-Forcer in Golang