Cross-compiling is the task every build engineer underestimates exactly once. The binary compiles, it links, it copies to the target — and then it dies with version 'GLIBC_2.34' not found, because the toolchain on your build host was built against a newer C library than the machine you are deploying to. The failure is not in your code. It is in the toolchain, and it usually surfaces after the artifact has already been promoted.
There are now three credible answers to “how do I build for another architecture without hand-assembling a toolchain,” and they represent three genuinely different philosophies: Zig treats cross-compilation as a first-class compiler feature, crosstool-NG treats it as a reproducible build product you configure and own, and riscv-gnu-toolchain treats it as a reference implementation for one architecture done properly.
If you maintain a self-hosted build farm — a runner that produces artifacts for arm64 appliances, RISC-V boards, or mixed-architecture fleets — the choice between them changes your build times, your maintenance load, and how often you get woken up.

TL;DR — Quick Verdict
For 90% of cross-compilation jobs, use Zig. zig cc is a drop-in C/C++ compiler that ships its own clang, LLVM, libc headers, and musl/glibc stubs, and it can target a specific glibc version so your artifact does not outrun your oldest supported target. No toolchain to build, no sysroot to assemble, no Docker image to maintain.
Use crosstool-NG when you must own the toolchain — a vendor requires a specific GCC version with specific patches, you need a tuple nobody ships binaries for, or you want bit-reproducible toolchains that you can rebuild in five years.
Use riscv-gnu-toolchain when your target is RISC-V and you need the canonical GCC toolchain, complete with multilib and glibc or newlib, matching what distro ports and hardware vendors actually test against.
Side-by-Side Comparison
| Dimension | Zig (zig cc) | crosstool-NG | riscv-gnu-toolchain |
|---|---|---|---|
| Core idea | Compiler with built-in cross targets | Configurable toolchain generator | Canonical RISC-V GCC build |
| Setup effort | Download a tarball, done | Configure, then build (tens of minutes to hours) | Clone, configure, make (tens of minutes) |
| Architectures | Very broad target list across Linux, macOS, Windows, bare metal | Whatever GCC/binutils/newlib/glibc support — effectively all | RISC-V only (rv32/rv64, many extensions) |
| C library control | musl, glibc (with version pinning), mingw, wasi | glibc, musl, uClibc-ng, newlib, several others | glibc (linux target) or newlib (bare-metal target) |
| Build reproducibility | High — versioned release artifact | High — that is the point of the config file | Medium — depends on your pinned submodules |
| GCC-specific patches | No — LLVM-based | Yes, full control over patch sets | Yes — arch-specific patches included |
| Multilib | Target-per-invocation | Configurable | Built-in (--enable-multilib) |
| Best fit | App-level C/C++/Rust/Go cgo builds | Vendor SDKs, embedded, long-lived products | RISC-V distros, boards, kernel-adjacent work |
| Maintenance load | Near zero | Ongoing — you own the config and the build | Low, but you rebuild when you bump the tag |
| Project traction | 43,263 stars on the GitHub mirror (development moved to Codeberg) | 2,522 stars, v1.29.0 released August 2026 | 4,669 stars, tagged builds through October 2026 |
Decision Matrix: Pick in Ten Seconds
| Your situation | Use | Why |
|---|---|---|
CI runner building arm64 images from amd64 | Zig | One download, -target flag, no sysroot archaeology |
| Rust or Go project with C dependencies | Zig | zig cc drops into existing build scripts as the C compiler |
| Vendor requires GCC 12.4 with their patch set | crosstool-NG | Only realistic way to own a patched GCC build |
Custom tuple (powerpc64le-unknown-linux-gnuabiv2-style) nobody ships | crosstool-NG | Generates tupled toolchains on demand |
| RISC-V board, kernel modules, glibc-matched userspace | riscv-gnu-toolchain | Canonical, vendor-tested RISC-V toolchain |
| RISC-V bare-metal firmware | riscv-gnu-toolchain (newlib) | Purpose-built newlib configuration |
| You need to ship one binary for 20 architectures | Zig | Each target is a flag, not a toolchain acquisition |
Zig: Cross-Compilation as a Compiler Feature
Zig’s argument is simple: the reason cross-compiling is painful is that compilers delegate the hard parts — libc headers, startup files, linker scripts — to pre-built sysroots. Zig ships them. zig cc is a clang driver that already has glibc headers for many versions, musl sources it compiles on demand, and startup objects for dozens of targets.
| |
That glibc version pin is the feature that makes Zig more than a convenience. With a conventional cross toolchain, the glibc you build against is whatever the toolchain was built against — you find out about the mismatch in production. With Zig you declare the floor: -target x86_64-linux-gnu.2.28 links against symbol versions available in glibc 2.28, so the binary keeps working on the older fleet.
The limits are equally concrete. Zig is not GCC; projects that depend on GCC-specific behaviour, plugin infrastructure, or -fanalyzer output will not be happy. If your build needs a patched GCC, Zig cannot substitute. And because a large part of Zig’s value is that it compiles C, adopting it usually means bolting it onto an existing build system — CC="zig cc" in a Makefile or a CMake toolchain file — rather than rewriting anything.
crosstool-NG: Own the Toolchain, Reproducibly
crosstool-NG (v1.29.0, August 2026, 2,522 stars, actively pushed this month) is a generator: you describe a toolchain as a config file, it builds the whole stack — binutils, GCC (or clang), C library, debug tools — from source, reproducibly.
| |
The output is yours: a self-contained toolchain with a .config file you commit alongside your source. Five years from now, that config still produces the same toolchain, which is exactly what regulated products and vendor SDKs need. It is also the only sane path when the tuple you need does not exist as a pre-built download.
The cost is time and attention. A full glibc toolchain build is a coffee-break-to-lunch operation on a decent machine, and it fails in the middle more often than a curl does — usually because a source tarball moved. Cache the build outputs in CI, pin every component version, and treat the toolchain itself as a versioned artifact rather than something you rebuild per pipeline run.
riscv-gnu-toolchain: The Canonical RISC-V Path
If your target is RISC-V, this is the reference. riscv-collab’s toolchain (4,669 stars, tags through October 2026) wraps binutils, GCC, glibc and newlib in one build system with the architecture and ABI knobs that RISC-V actually needs.
| |
The make linux versus make split trips people up constantly. make linux produces a glibc-based toolchain for userspace on Linux; make produces the newlib bare-metal toolchain for firmware. Building the wrong one does not fail loudly — it produces a toolchain that cannot link the thing you are building, hours later.
Multilib is the other reason to use this instead of a generic cross compiler: one toolchain can emit rv64gc/lp64d and rv32imac/ilp32 artifacts, which matters when a product family spans both. The trade is a longer build and a bigger install tree.
Testing Cross Artifacts Without Target Hardware
A cross-compiled binary you have not executed is a hypothesis. Two cheap ways to test it:
| |
readelf --version-info is the underrated check. It tells you the maximum glibc symbol version your binary demands, which is precisely the number that will cause a runtime failure on an older target. Wire it into CI as a gate: if the highest required version exceeds your oldest supported distribution, fail the build. For full-system testing rather than user-mode emulation, see our firmware emulation comparison of Renode, QEMU and gem5.
Pitfalls That Break Cross Builds
The sysroot is where cross builds actually fail. Compilers are easy; third-party libraries are not. Every cross build needs PKG_CONFIG_PATH, PKG_CONFIG_SYSROOT_DIR, and often --sysroot= pointed at the target tree, or your build silently picks up host headers and produces a binary with mismatched struct layouts.
Dynamic linking plus a newer build host equals a broken artifact. Even when the architecture is right, glibc symbol versions are not backward compatible in the direction people assume. Pin the glibc floor (-target ...gnu.2.28) or link statically with musl and stop worrying.
Static musl is not a universal answer. It is excellent for Go and Rust binaries and small C utilities. It is a poor fit for anything that needs NSS, locale data, or dlopen-based plugin loading.
Do not rebuild the toolchain per pipeline run. A toolchain is an input, not a build step. Cache it, version it, and pin its hash — otherwise your “reproducible” pipeline has a multi-hour, network-dependent step at its root.
Cross-compiling does not cross-test. Passing compilation and linking tells you almost nothing about runtime behaviour on a different page size, alignment rules, or endianness assumptions hiding in serialization code.
Mixed-toolchain builds hide in dependencies. If a Rust crate links C code with zig cc while the rest of the tree uses a crosstool-NG GCC, you now have two C runtimes in one binary. Pick one C toolchain per artifact.
For the deployment side of the same problem — running arm64 infrastructure without renting it — our arm64 self-hosting comparison covering Raspberry Pi 5, Hetzner Ampere and Oracle A1 covers cost and performance trade-offs, and the WebAssembly toolchain comparison is the adjacent case where your target is not an architecture but a virtual machine.
FAQ
Can Zig replace my existing GCC cross toolchain?
For application-level C and C++ builds, usually yes — CC="zig cc" plus a -target flag is often all it takes, and it removes the sysroot maintenance burden. It cannot replace a patched GCC for projects that depend on GCC-specific extensions, plugins, or vendor patch sets; for those, keep crosstool-NG.
Why does a binary that compiles fine fail with a GLIBC version error?
Because the toolchain linked against a newer glibc than the target has. Check the required versions with readelf --version-info and rebuild against an older symbol set — with Zig, -target x86_64-linux-gnu.2.28; with GCC toolchains, use an older sysroot.
Is crosstool-NG still worth it when distros ship cross compilers?
Yes, in two cases: a custom tuple that no distribution packages, and a requirement to own a specific patched GCC with a reproducible build recipe. If neither applies, a downloaded toolchain or zig cc will get you there faster with less to maintain.
make or make linux for riscv-gnu-toolchain?
make linux builds the glibc toolchain for Linux userspace. Plain make builds the newlib bare-metal toolchain for firmware. Choose before you start — the two produce incompatible toolchains, and the error only appears at link time.
How do I test cross-compiled binaries without target hardware?
Use user-mode emulation (qemu-aarch64, qemu-riscv64) with -L pointing at the target sysroot for quick functional checks, and reserve full-system emulation for anything touching hardware, kernel interfaces, or boot. Always pair it with readelf --version-info to catch the glibc-floor class of failures that only appear on older targets.
💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com