Compiling for Linux, macOS, and Windows
There are several different ways to compile our command-line application for different operating systems and we’ll go over examples of each of these. First, you can compile by building or installing your application:
- Building – Compiles the executable file and then moves it to the current folder or the filename indicated by the
–o
(output) flag - Installing – Compiles the executable file and then installs it to the
$GOPATH/bin
folder or$GOBIN
if it is set and caches all non-main packages, which are imported to the$
GOPATH/pkg
folder
Building using tags
In our previous chapter, Chapter 11, Custom Builds and Testing CLI Commands, we learned to build specifically for the macOS or Darwin operating system. To better understand how to use the build
command, we run go build –help
to see the usage:
mmontagnino@Marians-MacBook-Pro audiofile % go build -help usage: go build [-o output] [build flags...