Build Options, Cross-Compilation and Deployment
41.1 Important Build Flags
Optimized production build (-O3, strips debug, unused vars are errors) Output file name -cc gcc / clang / tcc / msvc Choose the C compiler
-cflags '-O3 -march=native' / -ldflags Pass flags to the C compiler/linker Debug info (V lines / C lines) -d name / -d name=value Define a compile-time flag -gc boehm / none Experimental automatic freeing
Drop unused code (smaller binaries; default in newer versions) Disable bounds checks (unsafe) Compress the binary with UPX Build a shared library -static / -cflags -static
-os windows / linux / macos / freebsd / android / wasm32_emscripten -arch amd64 / arm64 -b c / js / wasm / native Print the C compiler command Keep the generated C file Compiler phase timings -profile prof.txt Hot code reloading Cache compiled modules Allow __global variables -subsystem windows Windows GUI app (no console) No libc (kernels, bare metal) -message-limit N, -Wfatal-errors
41.2 Cross-Compilation
v -os windows -o app.exe app.v # Linux/macOS → Windows (needs MinGW-w64 cross compiler)
v -os linux -o app app.v # macOS/Windows → Linux (V downloads a cross toolchain/sysroot)
v -os macos app.v # needs the macOS SDK (osxcross)
vab build app.v # Android APK (vab tool)
v -cc 'zig cc' -cflags '-target aarch64-linux-musl' app.v # Zig as a cross C compiler41.3 Generated C and Embedding
v -o app.c app.v # emit the C source; compile anywhere with any C compiler
v -o app.c -os linux app.v # cross: generate C for another OS41.4 Deployment
Single static binaries (-prod -cflags -static, musl for Linux).
Docker multi-stage builds. systemd services. Reverse proxy for veb apps.
CI with GitHub Actions: vlang/setup-v action, v fmt -verify, v vet, v test, matrix builds.