6

I am trying to compile a C GUI application using GTK4. I was previously told here that both Ubuntu 21.04 and 21.10 would have both GTK3 and GTK4. However, when I installed Ubuntu 21.04 only GTK3 was present. I then did a dist-upgrade to 21.10 and found that both versions of GTK are native:

user@user: dpkg -l libgtk* | grep -e '^i' | grep -e 'libgtk-*[0-9]'
ii  libgtk-3-0:amd64           3.24.30-1ubuntu1 amd64        GTK graphical user interface library
ii  libgtk-3-bin               3.24.30-1ubuntu1 amd64        programs for the GTK graphical user interface library
ii  libgtk-3-common            3.24.30-1ubuntu1 all          common files for the GTK graphical user interface library
ii  libgtk-3-dev:amd64         3.24.30-1ubuntu1 amd64        development files for the GTK library
ii  libgtk-3-doc               3.24.30-1ubuntu1 all          documentation for the GTK graphical user interface library
ii  libgtk-4-1:amd64           4.4.0+ds1-5      amd64        GTK graphical user interface library
ii  libgtk-4-bin               4.4.0+ds1-5      amd64        programs for the GTK graphical user interface library
ii  libgtk-4-common            4.4.0+ds1-5      all          common files for the GTK graphical user interface library
ii  libgtk2.0-0:amd64          2.24.33-2ubuntu1 amd64        GTK graphical user interface library - old version
ii  libgtk2.0-bin              2.24.33-2ubuntu1 amd64        programs for the GTK graphical user interface library
ii  libgtk2.0-common           2.24.33-2ubuntu1 all          common files for the GTK graphical user interface library
ii  libgtk3-perl               0.038-1          all          Perl bindings for the GTK+ graphical user interface library

Just double checking the version of Ubuntu yields:

user@user: lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 21.10
Release:    21.10
Codename:   impish

The GTK page says to use the following to compile a GTK4 app using pkg-config:

gcc $( pkg-config --cflags gtk4 ) -o example-0 example-0.c $( pkg-config --libs gtk4 )

This is very similar to previous versions of GTK. For GTK3 it was:

gcc $( pkg-config --cflags gtk+-3.0 ) -o example-0 example-0.c $( pkg-config --libs gtk+-3.0 )

However, trying to compile the program using GTK4 results in:

user@user: make
Package gtk4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk4.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk4' found

So then based on here I ran:

user@user: pkg-config --variable pc_path pkg-config
/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig

Searching all of those paths, I only find GTK related .pc files in /usr/lib/x86_64-linux-gnu/pkgconfig and I do not find anything for GTK4. I do find gtk+-3.0.pc there though. So my question is, if GTK4 is native to Ubuntu 21.10, why would the pkg-config files be missing? Where do I obtain them so I can compile using pkg-config?

ASIDE: I do not have enough reputation to create the gtk4 tag. Could someone with enough reputation do so?

Leigh K
  • 363

1 Answers1

12

You will need to install libgtk-4-dev, with the command

sudo apt install libgtk-4-dev