Linux command
zig 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Compile and run a file
zig run [file.zig]
Build a project
zig build
Compile to executable
zig build-exe [file.zig]
Compile to object file
zig build-obj [file.zig]
Format Zig code
zig fmt [file.zig]
Run tests
zig test [file.zig]
Start REPL (interactive mode)
zig repl
说明
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.
参数
- -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
FAQ
What is the zig command used for?
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.
How do I run a basic zig example?
Run `zig run [file.zig]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -O _mode_ do in zig?
Optimization mode (Debug, ReleaseSafe, ReleaseFast, ReleaseSmall)