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.

Zig logo

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

DimensionZig (zig cc)crosstool-NGriscv-gnu-toolchain
Core ideaCompiler with built-in cross targetsConfigurable toolchain generatorCanonical RISC-V GCC build
Setup effortDownload a tarball, doneConfigure, then build (tens of minutes to hours)Clone, configure, make (tens of minutes)
ArchitecturesVery broad target list across Linux, macOS, Windows, bare metalWhatever GCC/binutils/newlib/glibc support — effectively allRISC-V only (rv32/rv64, many extensions)
C library controlmusl, glibc (with version pinning), mingw, wasiglibc, musl, uClibc-ng, newlib, several othersglibc (linux target) or newlib (bare-metal target)
Build reproducibilityHigh — versioned release artifactHigh — that is the point of the config fileMedium — depends on your pinned submodules
GCC-specific patchesNo — LLVM-basedYes, full control over patch setsYes — arch-specific patches included
MultilibTarget-per-invocationConfigurableBuilt-in (--enable-multilib)
Best fitApp-level C/C++/Rust/Go cgo buildsVendor SDKs, embedded, long-lived productsRISC-V distros, boards, kernel-adjacent work
Maintenance loadNear zeroOngoing — you own the config and the buildLow, but you rebuild when you bump the tag
Project traction43,263 stars on the GitHub mirror (development moved to Codeberg)2,522 stars, v1.29.0 released August 20264,669 stars, tagged builds through October 2026

Decision Matrix: Pick in Ten Seconds

Your situationUseWhy
CI runner building arm64 images from amd64ZigOne download, -target flag, no sysroot archaeology
Rust or Go project with C dependenciesZigzig cc drops into existing build scripts as the C compiler
Vendor requires GCC 12.4 with their patch setcrosstool-NGOnly realistic way to own a patched GCC build
Custom tuple (powerpc64le-unknown-linux-gnuabiv2-style) nobody shipscrosstool-NGGenerates tupled toolchains on demand
RISC-V board, kernel modules, glibc-matched userspaceriscv-gnu-toolchainCanonical, vendor-tested RISC-V toolchain
RISC-V bare-metal firmwareriscv-gnu-toolchain (newlib)Purpose-built newlib configuration
You need to ship one binary for 20 architecturesZigEach 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Cross-compile a C program for arm64 Linux
zig cc -target aarch64-linux-gnu hello.c -o hello-arm64

# Pin the glibc version so the artifact runs on older targets
zig cc -target x86_64-linux-gnu.2.28 hello.c -o hello-oldglibc

# Fully static RISC-V binary — no target sysroot involved
zig cc -target riscv64-linux-musl -static hello.c -o hello-riscv64

# See the real target list rather than trusting a blog post
zig targets | head -60

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Bootstrap crosstool-NG in local mode
./configure --enable-local && make

# Browse the shipped sample configurations
./ct-ng list-samples | grep -E "aarch64|riscv" | head

# Start from a sample, adjust, then build
./ct-ng aarch64-unknown-linux-gnu
./ct-ng menuconfig
./ct-ng build

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
git clone --recursive https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain

# Linux/glibc toolchain with multilib support
./configure --prefix=/opt/riscv --enable-multilib \
  --with-arch=rv64gc --with-abi=lp64d
sudo make linux

# Bare-metal alternative: newlib instead of glibc
./configure --prefix=/opt/riscv-newlib --with-arch=rv32imac --with-abi=ilp32
sudo make

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:

1
2
3
4
5
6
# Run an arm64 or riscv64 binary on an x86 host (user-mode emulation)
qemu-riscv64 -L /opt/riscv/sysroot ./hello-riscv64
qemu-aarch64 -L /usr/aarch64-linux-gnu ./hello-arm64

# Prove the glibc floor without running anything
readelf --version-info ./hello-oldglibc | grep GLIBC_ | tail -5

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