0Pricing
Zig Academy · Lesson

Targets and the -target Triple

Name the OS, arch, and ABI.

Targets and the -target Triple is a free Zig Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Cross-Compiling Is Built In

Zig ships every supported target inside the compiler, so cross-compilation needs no extra toolchains or downloads to begin.

The Target Triple

You name a target with a triple: it spells out the CPU architecture, the operating system, and the ABI in one string.

x86_64-linux-gnu

Three Parts, One String

Read a triple left to right as arch-os-abi. Each part narrows down exactly which binary the compiler should produce.

aarch64-macos-none

Pass It with -target

You select a target on the command line with the -target flag, and Zig builds for that machine instead of your own.

zig build-exe main.zig -target aarch64-linux-musl

The Architecture Part

The first field is the architecture, like x86_64, aarch64, or riscv64. It decides the instruction set of the output.

The OS Part

The middle field is the operating system, such as linux, macos, or windows. It shapes system calls and file formats.

The ABI Part

The last field is the ABI, like gnu, musl, or msvc. It picks the C library and calling conventions to match.

List Every Target

Not sure which triples exist? Ask Zig to print them all. zig targets dumps the supported architectures, OSes, and ABIs.

zig targets

Your Native Target

With no -target flag, Zig builds for the native triple: the same arch, OS, and ABI as the machine you are on.

Omitting Parts

You can leave fields off and Zig fills in a sensible default. x86_64-linux works because the ABI is chosen for you.

zig build-exe main.zig -target x86_64-linux

Tune the CPU Model

You can refine the architecture with a CPU model after a plus sign, asking Zig to use features of a specific processor.

zig build-exe main.zig -target x86_64-linux -mcpu=baseline

Quick Check

Recall the order of fields inside a target triple.

Recap

You learned that a target triple names arch, OS, and ABI, and that -target lets Zig build for any of them. 🌍

Frequently asked questions

Is the “Targets and the -target Triple” lesson free?

Yes — the full text of “Targets and the -target Triple” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.

What will I learn in “Targets and the -target Triple”?

Name the OS, arch, and ABI. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Zig Academy?

No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Targets and the -target Triple” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Zig Academy lesson?

Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Targets and the -target Triple
  2. Build for Linux, macOS, and Windows
  3. Cross-Compiling C with zig cc
  4. Static Binaries and musl
← Back to Zig Academy