Building a Linux Kernel Natively on macOS: A Journey Through Compilation Hell

2025-07-03
Building a Linux Kernel Natively on macOS: A Journey Through Compilation Hell

This post details the author's experience building a Linux kernel (RISC-V architecture) natively on macOS. The journey was fraught with challenges: an outdated make version, macOS's ld being incompatible with Linux expectations, missing elf.h and byteswap.h headers, and version conflicts with uuid_t and sed. The author overcame these by using Homebrew to install updated toolchains (make, llvm, lld, libelf, gnu-sed) and creating patches to address header file discrepancies and type definition conflicts. The kernel was successfully built, with macOS showing faster build times than Docker for clean builds, but slower incremental builds. The author concludes that fixing build issues is an ongoing, iterative process similar to continuous integration.

Development