Zig as a C/C++ Compiler and Toolchain

Zig ships libc headers and sources for many targets (glibc, musl, mingw-w64, macOS libSystem stubs, wasi-libc), so cross-compiling C/C++ needs no extra toolchain.

Caching, zig ar, zig ranlib, zig objcopy, zig dlltool, zig lib (MSVC-like lib.exe).

Rust cross-compilation: cargo-zigbuild uses zig cc as the linker.

zig cc -o hello hello.c                               # Clang-based drop-in for gcc/clang
zig c++ -std=c++20 -o app main.cpp
zig cc -target x86_64-windows-gnu -o hello.exe hello.c      # cross-compile C to Windows
zig cc -target aarch64-linux-musl -static -o hello hello.c  # static ARM64 Linux binary
zig cc -target x86_64-linux-gnu.2.17 hello.c                # target a specific glibc version
CC="zig cc" CXX="zig c++" ./configure && make               # use with autotools/make
cmake -DCMAKE_C_COMPILER="zig;cc" ...                        # with CMake (or a toolchain file)
CC="zig cc -target aarch64-linux-gnu" go build              # cgo cross-compilation with zig cc