111.Zig
安装 msys2
gcc 测试
https://www.mingw-w64.org/getting-started/msys2/
zig
安装
https://ziglang.org/learn/getting-started/
Introduction to Zig
https://cookbook.ziglang.cc/01-01-read-file-line-by-line.html
https://pedropark99.github.io/zig-book/Chapters/01-zig-weird.html
代码仓库
算法
https://www.hello-algo.com/chapter_hello_algo/
练习代码
https://gitee.com/gunhe/exercise_c
CH002
通过 zvm 来管理和安装不同的zig版本, 这个需要FQ, 否则速度特别慢.
https://github.com/tristanisham/zvm
curl https://raw.githubusercontent.com/tristanisham/zvm/master/install.sh | bash
# root@gtm001:~/exercise_c# curl https://raw.githubusercontent.com/tristanisham/zvm/master/install.sh | bash
# % Total % Received % Xferd Average Speed Time Time Time Current
# Dload Upload Total Spent Left Speed
# 100 5781 100 5781 0 0 11056 0 --:--:-- --:--:-- --:--:-- 11053
# Downloading zvm-linux-amd64.tar in /root/exercise_c
# wget is installed. Using wget...
# zvm.tar 100%[===========================================================================================================>] 9.88M 2.62MB/s in 3.9s
# Adding ZVM environment variables to /root/.bashrc
# Run 'source /root/.bashrc' to start using ZVM in this shell!
# Run 'zvm i master' to install Zig
source /root/.bashrc
# 安装master版本
zvm i master
zvm use master
# root@gtm001:~/exercise_c# zig version
# 0.15.0-dev.379+ffd85ffcd
# 切换版本
zvm i 0.14.0
zvm use 0.14.0
# root@gtm001:~/exercise_c# zig version
# 0.14.0
zvm list
# root@gtm001:~/exercise_c# zvm list
# 0.14.0
# master
zvm --version
zvm --help
# root@gtm001:~/exercise_c# zvm --help
# NAME:
# zvm - Zig Version Manager
# USAGE:
# zvm [global options] [command [command options]]
# VERSION:
# v0.8.6 linux/amd64
# DESCRIPTION:
# zvm lets you easily install, upgrade, and switch between different versions of Zig.
# COMMANDS:
# install, i download and install a version of Zig
# use switch between versions of Zig
# run run a command with the given Zig version
# list, ls list installed Zig versions. Flag `--all` to see remote options
# uninstall, rm remove an installed version of Zig
# clean remove build artifacts (good if you're a scrub)
# upgrade self-upgrade ZVM
# vmu set ZVM's version map URL for custom Zig distribution servers
# help, h Shows a list of commands or help for one command
# GLOBAL OPTIONS:
# --color value enable (on, yes/y, enabled, true) or disable (off, no/n, disabled, false) colored ZVM output (default: "toggle")
# --help, -h show help
# --version, -v print the version
# COPYRIGHT:
# Copyright © 2025 Tristan Isham
zig build-exe
使用 build-lib 构建静态库文件和动态共享库文件
zig build-exe --verbose-cc myprog.c mylib.c -lc
./myprog
# Enter two float values: 2
# 3
# 2.000000 and 3.000000
# 3.000000 is the biggest
zig build-lib
静态库
apt install file -y
file libmylib.a
浙公网安备 33010602011771号