Cross-Compiling Your Application

Powerful Command-Line Applications in Go — by Ricardo Gerardi (122 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Conditionally Building Your Applic ation | TOC | Compiling Your Go Application for Co ntainers 👉

Unlike interpreted languages such as Python or Nodejs, Go is a compiled language, which means it produces a binary executable file that contains all the requirements to run your application.

When you’re planning to distribute your application, this is a major benefit as users can run your application by running the binary executable without having to install any interpreters or runtimes. This makes Go applications extremely portable.

When building the executable file, Go creates a file that contains instructions that are specific for a target operating system and architecture. Because of this, you can’t take a file that is compiled for Linux and try to run it on Windows, or a file that was compiled for the Linux x86_64 architecture and try to run it on the Linux ARM system.

To help you with that, Go allows you to cross-compile or cross-build your applications. You can use the Go tools such as go build to compile a binary file for supported operating systems and architectures from a single platform. For example, if you’re running Go on Linux, you can compile a binary for Linux but also for Windows, macOS, and different CPU architectures. To see a list of supported combinations of operating systems and architectures, use go tool dist…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.