Help compiling GTK4

I’ve followed the instructions in

In my case it was:

meson setup --prefix /home/carlos/Desktop/gtk4 build

After than, when running ninja, I got:

Couldn't find include 'GdkPixbuf-2.0.gir' (search path: '['/home/carlos/Desktop/gtk/build/gtk', '/usr/share/gir-1.0', '/home/carlos/Desktop/gtk/build/gtk', '/usr/share', '/usr/share/ubuntu/gir-1.0', '/usr/local/share/gir-1.0', '/usr/share/gir-1.0', '/var/lib/snapd/desktop/gir-1.0', '/usr/share/gir-1.0', '/usr/share/gir-1.0']')

But the gir was indeed created inside the gdk-pixbuf subproject:

carlos@carlos:~/Desktop/gtk/build$ find ../ -name GdkPixbuf-2.0.gir

which is not in the search path listed in the error above.

Am I doing something wrong?

If you don’t need introspection data, you may want to use:

meson setup --prefix ~/Desktop/gtk4 -Dintrospection=disabled _build .

to set up the build.

Alternatively, you can install the development package for gdk-pixbuf that comes with your distribution; GTK does not require a bleeding edge version of gdk-pixbuf, and the subproject is mostly there for building GTK on macOS and Windows.

Alternatively, you can install the development package for gdk-pixbuf that comes with your distribution

Thanks! For pixbuf that did the trick, but unfortunately for pango the version provided by my system was too old for the build requirements. I think I don’t want to disable introspection altogether because I’m going to use this from python. What would be the best way to proceed given that I already have the pango submodule?

There are still some issues in the interaction between introspection and subprojects.

The easiest route may be to just build the gtk dependencies independently, and install them (with introspection enabled).

I think this is an issue between gobject-introspection and Meson, when using subprojects.

A solution that does not involve disabling introspection is to use jhbuild. That will install all the dependencies in a separate prefix and avoid subprojects altogether.

Ok, I managed to build gtk4 in two different ways according to your suggestions:

  1. First build pango and graphene from the subprojects directory and add them to PKG_CONFIG_PATH and XDG_DATA_DIRS, then build gtk4 itself.

  2. Use jhbuild. This tool is very convenient! It’s the first time I use it. The complexity of the build was quite impressive, even gstreamer bad plugins were built. I set shallow_clone = True in jhbuildrc to avoid huge clones. I had to manually install libudev-dev because it wasn’t automatically installed. Other than that, everything went ok.

After the build I set LD_LIBRARY_PATH and XDG_DATA_DIRS:

export LD_LIBRARY_PATH=/home/carlos/jhbuild/install/lib

but when I run this minimal python snippet:

import gi

gi.require_version("Gtk", "4.0")
from gi.repository import Gtk

I get:

  File "/usr/lib/python3/dist-packages/gi/", line 145, in load_module
    dynamic_module = load_overrides(introspection_module)
  File "/usr/lib/python3/dist-packages/gi/overrides/", line 118, in load_overrides
    override_mod = importlib.import_module(override_package_name)
  File "/usr/lib/python3.8/importlib/", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/lib/python3/dist-packages/gi/overrides/", line 168, in <module>
    class Container(Gtk.Container, Widget):
  File "/usr/lib/python3/dist-packages/gi/", line 123, in __getattr__
    raise AttributeError("%r object has no attribute %r" % (
AttributeError: 'gi.repository.Gtk' object has no attribute 'Container'

GIR files seem to be correctly generated at /home/carlos/jhbuild/install/share/gir-1.0/. I also tried putting ~/jhbuild/install/share at the beginning of XDG_DATA_DIRS, to no avail.

Do you have any idea about what may be happening? Do I need an updated version of python gi ? There are some python modules in ~/jhbuild/install/lib/python3.8/site-packages but gi is not one of them.

Yes, you need to build pygobject from the main development branch.

Ok, that did it, thanks! I had to first install pycairo in the venv in order to build and install pyobject, I think build_ext required it, is that normal?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.