Building for macOS on Linux or Windows

Cross-compiling for mac requires that the macOS SDK is available to link against. When building from a Linux or Windows computer, we must download and install the SDK and also update our build toolchain to use it. The easiest way to do this is with the osxcross tool. The details for this setup can be found in the Cross compiling for macOS with CGo section of an AppendixCross-Compiler Setup. The main steps are outlined here for quick reference using a Linux terminal—the Windows setup is similar once you have installed the cygwin or mingw terminals.

First, we need to download the macOS SDK, which is bundled with Xcode. Download XCode.dmg from the Apple download site at https://developer.apple.com/download/more/?name=Xcode%207.3 (7.3.1 is recommended for osxcross). Next, install the osxcross tools from github.com/tpoechtrager/osxcross (full installation details are available at that URL or in the Appendix). Completing the installation will have extracted the macOS SDK and created the compilation toolchain that will build against these installed APIs.

And now we are ready to build. As well as the previous environment variables, we add CC=o32-clang, after which our build command should succeed. Here you can see that our Linux computer managed to create a macOS 64-bit Mach-O executable file named hello:


Using osxcross (o32-clang), we built a macOS-native UI application on Linux.

The process for Windows is similar and full details can be found in the Cross compiling for macOS with CGo section of an AppendixCross-Compiler Setup.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.239.41