LinuxCommandLibrary

zig

Systems programming language and compiler

TLDR

Compile and run a file

$ zig run [file.zig]
copy
Build a project
$ zig build
copy
Compile to executable
$ zig build-exe [file.zig]
copy
Compile to object file
$ zig build-obj [file.zig]
copy
Format Zig code
$ zig fmt [file.zig]
copy
Run tests
$ zig test [file.zig]
copy
Start REPL (interactive mode)
$ zig repl
copy

SYNOPSIS

zig [command] [options] [arguments]

DESCRIPTION

Zig is a systems programming language focused on safety, performance, and maintainability. The zig command is both a compiler and build system.
Key features include compile-time code execution (comptime), optional safety checks, C interoperability, and built-in cross-compilation to many targets without external toolchains.
Zig can also serve as a drop-in C/C++ compiler (zig cc, zig c++) with consistent cross-compilation capabilities, making it useful even for non-Zig projects.
The build system uses build.zig files written in Zig itself, providing full language power for build configuration.

PARAMETERS

-O mode

Optimization mode (Debug, ReleaseSafe, ReleaseFast, ReleaseSmall)
-target triple
Cross-compilation target
-I dir
Add include directory
-l lib
Link library
-femit-asm
Output assembly
-freference-trace
Show compile error reference traces

SUBCOMMANDS

build

Build project using build.zig
build-exe
Compile to executable
build-lib
Compile to library
build-obj
Compile to object file
run
Compile and run immediately
test
Run unit tests
fmt
Format source code
cc
Use Zig as a C compiler
c++
Use Zig as a C++ compiler
translate-c
Translate C code to Zig
init-exe
Initialize executable project
init-lib
Initialize library project

CAVEATS

Zig is still pre-1.0 and the language/standard library may change between versions.
Debug builds include runtime safety checks that catch bugs but have performance overhead.
Cross-compilation is powerful but target-specific system libraries may still be needed for some features.

SEE ALSO

gcc(1), clang(1), rustc(1), make(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community