0Pricing
Zig Academy · Lección

Destinos y la terna -target

Especifique el sistema operativo, la arquitectura y la ABI.

Destinos y la terna -target es una lección gratuita de Zig Academy en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Zig Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Zig Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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. 🌍

Preguntas frecuentes

¿La lección «Destinos y la terna -target» es gratis?

Sí — el texto completo de «Destinos y la terna -target» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Zig Academy, actualiza a CoddyKit PRO. El curso de Zig Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Destinos y la terna -target»?

Especifique el sistema operativo, la arquitectura y la ABI. Practicas Zig Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Zig Academy?

No se requiere experiencia previa. Zig Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.

¿Cuánto tiempo toma la lección «Destinos y la terna -target»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Zig Academy?

Sí. Cada lección de Zig Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Destinos y la terna -target
  2. Compilar para Linux, macOS y Windows
  3. Compilación cruzada de C con zig cc
  4. Binarios estáticos y musl
← Volver a Zig Academy