GTK; trouble compiling on Ubuntu 22.04


Git1

Very Active Member
Joined
Dec 23, 2020
Messages
282
G'day folks,
So I'm trying to get into gtk in C, but am getting odd errors when compiling just the 'Hello World' examples from gtk.org here and here.

With a copy/paste of the second example, I get the following output:

$ gcc $(pkg-config --cflags gtk4) -o hello-world-gtk hello-world-gtk.c $(pkg-config --libs gtk4)
hello-world-gtk.c: In function ‘main’:
hello-world-gtk.c:37:49: error: ‘G_APPLICATION_DEFAULT_FLAGS’ undeclared (first use in this function); did you mean ‘G_APPLICATION_GET_CLASS’?
37 | app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
| G_APPLICATION_GET_CLASS
hello-world-gtk.c:37:49: note: each undeclared identifier is reported only once for each function it appears in


I've tried with gtk3 and 4, but get similar results. Is it a missing library or something perhaps? I'm on Ubuntu 22.04 and have installed the dev packages for both 3 & 4.

Any help is appreciated. :)
 
Are you sure your hello world program is for gtk3+ and not for gtk-2.0?

Well, no, not really. The first example gives no hint as to required version#, and the compile instructions provided in the second example show gtk4, so I assumed that was the requirement, thus why I updated from 3 to 4, but still no joy.

I find it rather odd that the official gtk site doesn't actually mention which versions the examples are intended for. I've read that gtk is not backwards compatible, so version requirements would be extremely useful info!


Anyway, thanks a lot for your reply; I'll try 2.0 tomorrow and report back.
 
A.I. says that is related to GLib not GTK

G_APPLICATION_DEFAULT_FLAGS
is a modern constant in the GLib/GTK development library (since GLib 2.74, replacing G_APPLICATION_FLAGS_NONE) used with gtk_application_new() to signify standard application behavior
  • Replaces G_APPLICATION_FLAGS_NONE: It's the recommended replacement for G_APPLICATION_FLAGS_NONE (value 0) in newer GLib versions (>= 2.74) for simplicity.
  • Compatibility: If you need to support older GLib versions (before 2.74), you might use conditional compilation (#if GLIB_CHECK_VERSION) or simply use 0 (the value of G_APPLICATION_FLAGS_NONE) as a fallback.
 
Back
Top