zig run versus zig build-exe
Execute rapidamente ou produza um binário real.
zig run versus zig build-exe é 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.
Two Ways to Run Code
Zig gives you two main paths from source to result: zig run for quick iteration, and zig build-exe when you want a standalone binary to keep.
zig run: Compile and Go
The command zig run compiles your file and immediately executes it, all in one step. Nothing is left behind on disk afterward.
zig run main.zigPerfect for Iteration
Because it skips saving a file, zig run is ideal while you are still experimenting. Change code, run again, and see output in seconds.
zig build-exe: Make a Binary
When you want an executable you can ship or run later, use zig build-exe. It compiles your source into a real file on disk.
zig build-exe main.zigWhere the Binary Lands
By default the output is named after your file, like main, and placed in the current directory. You then run it yourself.
./mainNaming the Output
You can choose the binary name with the -femit-bin flag. This is handy when one source file should produce a specifically named tool.
zig build-exe main.zig -femit-bin=helloRun Caches Too
Even zig run builds a binary behind the scenes and caches it. A second run with no changes reuses that cache and starts almost instantly.
Passing Arguments
With zig run, anything after -- is forwarded to your program as its command-line arguments rather than to the compiler.
zig run main.zig -- --name Adabuild-exe Is Lower Level
zig build-exe is a direct compiler command for a single artifact. For full projects you will later graduate to zig build with a build.zig file.
Quick Decision Rule
Ask one question: do I need to keep this binary? If no, reach for zig run. If yes, reach for zig build-exe and grab the output file.
Same Compiler, Different Goal
Both commands use the very same Zig compiler, so the code that runs is identical. Only the convenience and the leftover file differ.
Quick Check
You are testing a tiny script and do not need to keep any file around. Which command fits best?
Recap
You now have two tools: zig run for fast compile-and-go iteration, and zig build-exe to produce a real binary you can name, keep, and ship. 🚀
Perguntas Frequentes
A aula “zig run versus zig build-exe” é grátis?
Sim — o texto completo de “zig run versus zig build-exe” é 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 “zig run versus zig build-exe”?
Execute rapidamente ou produza um binário real. 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 “zig run versus zig build-exe”?
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
- zig run versus zig build-exe
- Debug, ReleaseSafe, ReleaseFast
- Lendo erros do compilador
- zig fmt: formate seu código