To install the dependencies for cross compiling for Linux, we'll use the Homebrew package manager again—see the previous sections or https://brew.sh/ for installation instructions. Using Homebrew, we'll install the appropriate packages by opening a Terminal and executing the following commands (the HOMEBREW_BUILD_FROM_SOURCE variable works around an issue with musl-cross depending on potentially old versions of libraries):
- export HOMEBREW_BUILD_FROM_SOURCE=1
- brew install FiloSottile/musl-cross/musl-cross
Once the installation is complete (this may take some time as it's building a complete compiler toolchain from source), you should be able to build for Linux. To do so, you'll need to set the environment variables, CC=x86_64-linux-musl-gcc and CXX=x86_64-linux-musl-g++.