Also known as: cross-compiling, cross compiler
Cross-compilation is building an executable on one platform — the host — that is meant to run on a different platform — the target — such as producing a Windows or macOS binary from a Linux machine without ever touching those operating systems.1
How it works
A normal compiler emits machine code for the machine it runs on. A cross-compiling toolchain instead targets a chosen operating system and CPU architecture, generating code and linking against the right libraries for that target. The output is a binary that will not run on the host but will run on the target.1 This is essential whenever the target cannot easily build for itself — embedded devices, phones, or simply a release pipeline that produces every platform’s download from one build machine.
Trade-offs
Cross-compilation removes the need to own or maintain a machine of every target type, making multi-platform releases a single automated step. The complications come from platform-specific dependencies: code that links against C libraries or calls operating-system APIs may need matching target headers and libraries, and that setup can be fiddly. Languages with little native dependency and a pure toolchain cross-compile most smoothly, especially when they also emit a static binary.1
In practice
Go makes cross-compilation a one-line affair — setting
GOOS and GOARCH builds for any supported platform from any host — which is part of
why GopherTrunk can ship Linux, macOS, and Windows downloads from one build.
Rust supports many targets through its toolchain, and
C cross-compiles with dedicated toolchains, though external
dependencies make it more involved.
Sources
-
Cross compiler — Wikipedia, on building executables for a target platform different from the host and why it matters for releases and embedded work. ↩ ↩2 ↩3