Alvos e a tripla -target
Nomeie o OS, a arquitetura e a ABI.
Alvos e a tripla -target é uma aula grátis de Zig Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Zig Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Zig Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em 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-gnuThree 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-nonePass 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-muslThe 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 targetsYour 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-linuxTune 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=baselineQuick 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. 🌍
Perguntas Frequentes
A aula “Alvos e a tripla -target” é grátis?
Sim — o texto completo de “Alvos e a tripla -target” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Zig Academy, atualize para CoddyKit PRO. O curso de Zig Academy inclui 4 aulas no total.
O que vou aprender em “Alvos e a tripla -target”?
Nomeie o OS, a arquitetura e a ABI. Você pratica Zig Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Zig Academy?
Nenhuma experiência prévia é necessária. Zig Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.
Quanto tempo leva a aula “Alvos e a tripla -target”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Zig Academy?
Sim. Cada aula de Zig Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Alvos e a tripla -target
- Compile para Linux, macOS e Windows
- Compilação cruzada de C com zig cc
- Binários estáticos e musl