I have gtk 3 & 4 installed, how can I use 4 in meson

I’m doing a meson tutorial and it uses a meson.build file with the following text

project('tutorial', 'c')
gtkdep = dependency('gtk+-3.0')
executable('demo', 'main.c', dependencies : gtkdep)

The demo works fine but if I change the 3 in the second line to 4 I get the following error in response to ‘meson compile’.

../meson.build:2:0: ERROR: Dependency "gtk+-4.0" not found, tried pkgconfig and cmake

I’m totally lost here.
It’s so long since I installed gtk4 I can’t remember how I did it but I think it was using pamac or pacman. I don’t recall installing gtk3 (getting gtk4 was the reason I moved from ubuntu) so I’m puzzled why gtk3 is there unless it’s a dependency of 4.
I’ve also no idea why there’s a plus sign after the ‘gtk’.

Anyone help.


gtkdep = dependency('gtk4')

Thanks Yochanan. This time it found the library although it’s no longer working due to not finding some functions in the main.c file. The errors are

[1/2] Compiling C object demo.p/main.c.o
../main.c: In function ‘activate’:
../main.c:13:3: warning: implicit declaration of function ‘gtk_container_add’ [-Wimplicit-function-declaration]
   13 |   gtk_container_add (GTK_CONTAINER (window), label);
      |   ^~~~~~~~~~~~~~~~~
../main.c:13:22: warning: implicit declaration of function ‘GTK_CONTAINER’; did you mean ‘GTK_CONSTRAINT’? [-Wimplicit-function-declaration]
   13 |   gtk_container_add (GTK_CONTAINER (window), label);
      |                      ^~~~~~~~~~~~~
      |                      GTK_CONSTRAINT
../main.c:16:3: warning: implicit declaration of function ‘gtk_widget_show_all’; did you mean ‘gtk_widget_show’? [-Wimplicit-function-declaration]
   16 |   gtk_widget_show_all(window);
      |   ^~~~~~~~~~~~~~~~~~~
      |   gtk_widget_show

but I’m assuming this is down to differences between 3 & 4.

I believe so, yes.

Tip: When pasting terminal output on Discourse forums, one can either…

  • Use the Preformatted text </> toolbar button–NOT the Quote " button.

  • Add three backticks ` above and below the text (Markdown):

    type or paste code here

  • Use HTML:

    type or paste code here

Please edit your posts accordingly.

EDIT: I’ve done it for you. See the difference? :wink:

Indeed Yochanan, thanks but where do I find these toolbar buttons.

PS The first line in main.c is

#include <gtk/gtk.h>

How do I know if that’s the include file for gtk 3 or 4.


1 Like

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