Cross compilation

Cross compilation is supported for Windows, Linux and FreeBSD.

To cross compile your project simply run:

v -os windows .

or

v -os linux .

or

v -os freebsd .

[!NOTE] Cross-compiling a Windows binary on a Linux machine requires the GNU C compiler for MinGW-w64 (targeting Win64) to first be installed.

For Ubuntu/Debian-based distributions:

sudo apt install gcc-mingw-w64-x86-64

For Arch based distributions:

sudo pacman -S mingw-w64-gcc

(Cross compiling for macOS is temporarily not possible.)

If you don't have any C dependencies, that's all you need to do. This works even when compiling GUI apps using the ui module or graphical apps using gg.

If you need a custom cross compiler, pass -cc <compiler> for one build, or set VCROSS_COMPILER_NAME in your environment. Example:

v -os linux -cc cosmocc .

You will need to install Clang, LLD linker, and download a zip file with libraries and include files for Windows and Linux. V will provide you with a link.