We're hiring!
*

Build and run GTK 4 applications with Visual Studio

Xavier Claessens avatar

Xavier Claessens
March 18, 2021

Share this post:

Reading time:

Over the past few months, I've been working on a side project to improve Meson sub-project support. The best stress test is to build projects on Windows, without msys2, because it has no dependencies or tools installed (e.g. pkg-config). Meson has to build everything itself from scratch.

Here are step-by-step instructions, starting from a fresh Windows 10 installation, on how to run a gtk4-demo application.

Install Visual Studio

Download from https://visualstudio.microsoft.com/vs/community. Make sure to check the box "Desktop development with C++".

Collabora - Installing Visual Studio

Install Python >= 3.6

Download from https://www.python.org/downloads. Make sure to check the box "Add python to PATH".

Collabora - Installing Python

Install Git for Windows

Download from https://gitforwindows.org. It asks many questions, however the default is always good enough, so next, next, next...

Collabora - Installing Git for Windows

Open developer terminal

From the Windows start menu, search for x64 Native Tools Command Prompt for VS 2019. That will open a terminal configured to use MSVC x64 tools.

Collabora - Visual Studio Developer Command Prompt

First let's create a directory where we'll fetch the source code:

mkdir C:\src
cd C:\src

Let's also configure git:

git config --global user.email "xavier.claessens@collabora.com"
git config --global user.name "Xavier Claessens"

Install Meson

Installing the latest release of Meson (requires >=0.57.0) can be done with a simple command:

C:\src>pip install meson

Fetch GTK4 source

Fetch gtk from git:

C:\src>git clone https://gitlab.gnome.org/GNOME/gtk.git
C:\src>cd gtk

At the time of writing !3135 is not yet merged, so we need to use my branch:

(Update March 22: This has now been merged so my branch is no longer needed.)

C:\src\gtk>git fetch https://gitlab.gnome.org/xclaesse/gtk.git meson-install-script
C:\src\gtk>git checkout -b meson-install-script FETCH_HEAD

Build GTK4 with all its dependencies

During the GTK4 configuration, Meson will download and configure all dependencies. Great efforts have been made across all dependencies to make them work out of the box on Windows.

C:\src\gtk>meson setup build --prefix C:/gnome
C:\src\gtk>meson compile -C build
C:\src\gtk>meson install -C build

Collabora - GTK4 configuration

Run gtk4-demo

That's all, you can now run demo applications!

C:\src\gtk>C:\gnome\bin\gtk4-demo.exe

Collabora - Running gtk4-demo.exe

It works out of the box on my VirtualBox machine, however on my physical PC with an intel GPU, I get a crash at startup:

Unhandled exception at 0x5211345E (ig4icd32.dll) in gtk4-demo.exe: 0xC0000005: Access violation reading location 0x00000050

This can be worked around by using cairo rendering:

C:\src\gtk>set GSK_RENDERER=cairo
C:\src\gtk>C:\gnome\bin\gtk4-demo.exe

Debug in Visual Studio

Since this is a complete build using MSVC, it is also fully debuggable.

  • Open Visual Studio
  • Click "Open a project or solution"
  • Browse to C:\gnome\bin\gtk4-demo.exe
  • Click "Start" button

If you break execution, or hit a crash, it will open the source code and you can debug step by step, see the value of any variable, whether it is in gtk or in any of its dependencies.

Debugging in Visual Studio.

What's next?

Here's a list of some of the items I would like to eventually look into:

  • See if we can use GTK4 as sub-project of a real application. Which applications do we have that are ported to GTK4 already and runs on Windows? Gedit?
  • Add GStreamer gst-build as a sub-project of GTK4 to build the media player? This would probably lead to a world record of number of Meson subprojects built at once.
  • Add Windows CI to GTK4?

As usual, if you have any questions about GTK4 or GStreamer on Windows, or any other platform, please contact us!


Add a Comment

Search the newsroom

Latest Blog Posts

Running Mainline Linux, U-Boot, and Mesa on Rockchip: A year in review

02/03/2026

Get the recap of Nicolas Frattaroli's FOSDEM talk detailing Rockchip’s mainline progress, including Vulkan 1.4 and NPU support as a vital…

Now streaming: Collabora XDC 2025 presentations

02/12/2025

As an active member of the freedesktop community, Collabora was busy at XDC 2025. Our graphics team delivered five talks, helped out in…

Implementing Bluetooth LE Audio & Auracast on Linux systems

24/11/2025

LE Audio introduces a modern, low-power, low-latency Bluetooth® audio architecture that overcomes the limitations of classic Bluetooth®…

Strengthening KernelCI: New architecture, storage, and integrations

17/11/2025

Collabora’s long-term leadership in KernelCI has delivered a completely revamped architecture, new tooling, stronger infrastructure, and…

Font recognition reimagined with FasterViT-2

11/11/2025

Collabora extended the AdobeVFR dataset and trained a FasterViT-2 font recognition model on millions of samples. The result is a state-of-the-art…

Expanding access to XR: Google Cardboard comes to Monado

31/10/2025

Collabora has advanced Monado's accessibility by making the OpenXR runtime supported by Google Cardboard and similar mobile VR viewers so…

Open Since 2005 logo

Our website only uses a strictly necessary session cookie provided by our CMS system. To find out more please follow this link.

Collabora Limited © 2005-2026. All rights reserved. Privacy Notice. Sitemap.