Windows cross-build sample ​
Cross-compiling a Vala (or C/GTK) project for Windows from Linux, based on the archived GNOME Wiki page Projects/Vala/Win32CrossBuildSample.
The wiki walked through CMake, an old MinGW toolchain (i586-mingw32msvc), GTK+Â 2 bundles, and NSIS packaging. Those pieces are mostly historical: current developers typically use Meson with a MinGW-w64 toolchain and GTKÂ 3 or GTKÂ 4 Windows runtimes from gvsbuild or similar distributors.
What the wiki described (CMake + GTK+ 2 bundle) ​
The archive suggested:
- Installing
mingw32, CMake, NSIS, and a pre-built GTK+ bundle for Windows. - Unzipping the bundle under
win32/and rewriting every.pcfile’sprefix=soPKG_CONFIG_PATHpoints at the bundle. - A
Toolchain.cmakethat setsCMAKE_SYSTEM_NAMEtoWindowsand selectsi586-mingw32msvc-gcc. - A tiny
hello-world.clinked withgtk+-2.0to prove the cross prefix works, then running the.exewith Wine.
That flow is useful as background reading, but the exact package names, URLs, and compiler triples on modern distributions differ. Treat the wiki as a narrative, not copy-paste instructions.
Meson cross-compilation for Windows ​
Meson is the build system most Vala and GTK projects use today. A typical approach:
- Install a MinGW-w64 cross compiler (for example
x86_64-w64-mingw32-gccon Debian/Ubuntu viagcc-mingw-w64-x86-64). - Install or build Windows copies of GLib/GTK and produce a pkg-config tree (gvsbuild output is common).
- Write a Meson cross file describing the host system and tool paths.
mingw-w64.ini (adjust paths to your SDK root):
[binaries]
c = 'x86_64-w64-mingw32-gcc'
cpp = 'x86_64-w64-mingw32-g++'
ar = 'x86_64-w64-mingw32-ar'
strip = 'x86_64-w64-mingw32-strip'
pkg-config = 'pkg-config'
windres = 'x86_64-w64-mingw32-windres'
[built-in options]
c_args = ['-I/path/to/windows-deps/include']
c_link_args = ['-L/path/to/windows-deps/lib']
[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
[properties]
pkg_config_libdir = '/path/to/windows-deps/lib/pkgconfig'meson.build:
project('hello', 'c', vala: true)
glib_dep = dependency('glib-2.0')
exe = executable('hello', 'main.vala', dependencies: glib_dep)Configure and compile from your project root:
export PKG_CONFIG_PATH=/path/to/windows-deps/lib/pkgconfig
meson setup build-windows --cross-file mingw-w64.ini
meson compile -C build-windowsMeson then passes the correct --pkg arguments to valac and links against the Windows libraries described by the cross environment. Copy required DLLs next to the .exe (or run an install step that stages a runtime tree) before testing on Windows.
For GTK applications, follow upstream guidance for GTK on Windows and keep your SDK versions aligned with what your dependencies expect.
