Zig Compiler CLI Reference
Complete reference for all Zig compiler commands, options, and flags.Commands
Project Management
zig build
Build project from build.zig.
zig init
Initialize a Zig package in the current directory.
build.zig and source files.
zig fetch
Copy a package into global cache and print its hash.
build.zig.zon.
Compilation Commands
zig build-exe
Create executable from source or object files.
- Example
- With C Files
zig build-lib
Create library from source or object files.
- Static Library
- Dynamic Library
zig build-obj
Create object file from source.
.o (or .obj on Windows) object file.
zig test
Perform unit testing.
zig test-obj
Create object file for unit testing.
.o or .obj) that can be linked with other test code.
zig run
Create executable and run immediately.
-- are passed to the program.
Code Tools
zig fmt
Reformat Zig source into canonical form.
- Format Files
- Check Only
zig ast-check
Look for simple compile errors in any set of files.
zig reduce
Minimize a bug report.
zig translate-c
Convert C code to Zig code.
The generated Zig code may require manual adjustments for idiomatic Zig patterns.
C/C++ Compatibility
Zig can be used as a drop-in replacement for various C/C++ tools:zig cc
Use Zig as a drop-in C compiler.
zig c++
Use Zig as a drop-in C++ compiler.
zig ar
Use Zig as a drop-in archiver.
Other Tools
zig dlltool- Windows DLL toolzig lib- Windows lib.exe replacementzig ranlib- Generate archive indexzig objcopy- Copy and translate object fileszig rc- Windows resource compiler
Information Commands
zig version
Print version number and exit.
zig env
Print lib path, std path, cache directory, and version.
zig targets
List available compilation targets.
zig libc
Display native libc paths file or validate one.
zig std
View standard library documentation in a browser.
zig zen
Print Zen of Zig and exit.
General Options
Help
Color Output
auto.
- Auto (default)
- Force On
- Force Off
Concurrency
Build Artifacts
Binary Output
Assembly Output
LLVM IR Output
LLVM Bitcode Output
C Header Output
Documentation Output
Import Library (Windows)
Cache Directories
Compilation Name
The name affects the output filename and library names, but is not a file path.
Supported File Types
| Extension | Type | Description |
|---|---|---|
.zig | Zig source | Zig source code |
.o | Object | ELF/Mach-O/WebAssembly object |
.obj | Object | COFF (Windows) object |
.a | Archive | Static library (ELF/Mach-O/Wasm) |
.lib | Archive | COFF static library |
.so | Shared | ELF shared object |
.dll | Shared | Windows dynamic library |
.dylib | Shared | macOS dynamic library |
.tbd | Text | macOS text-based dylib definition |
.s | Assembly | Target-specific assembly |
.S | Assembly | Assembly with C preprocessor |
.c | C source | C source (requires LLVM) |
.cpp, .cc, .cxx, .C, .c++ | C++ source | C++ source (requires LLVM) |
.m | Obj-C | Objective-C (requires LLVM) |
.mm | Obj-C++ | Objective-C++ (requires LLVM) |
.bc | LLVM | LLVM IR Module (requires LLVM) |
Next Steps
Compilation Modes
Learn about Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall modes
Optimization
Understand optimization levels and strategies
Debugging
Debug Zig programs effectively
C Interop
Work with C code and libraries