I'm trying to build an helloworld window with Gtk and glade. The code compiles fine but on runtime it fails on gtk_builder_add_from_file. The strange thing is that the error reports a current gtk version different to the one I get with gtk_get_major_version/gtk_get_minor_version.
GtkBuilder *builder;
GtkWidget *window;
GError *err = NULL;
gtk_init(NULL,NULL);
printf("maj %d, min %d\n",gtk_get_major_version (),gtk_get_minor_version ());
builder = gtk_builder_new();
gtk_builder_add_from_file (builder, "/path/to/ui.glade", &err);
if (err != NULL)
{
printf ("%s\n", err->message);
g_error_free (err);
}
window = GTK_WIDGET(gtk_builder_get_object(builder, "mywin"));
gtk_widget_show(window);
g_object_unref(builder);
gtk_main();
...
Stdout:
maj 3, min 2
/path/to/ui.glade: required gtk+ version 3.2, current version is 2.24
There is no doubt that the glade file was created using Glade 3.x while your application was compiled against Gtk version 2.x.
If you've created the glade file on your computer then chances are that your have both runtime and developer files for Gtk 2 and Gtk 3.
If so, then you must change your compile instructions to link against Gtk 3. For that check you pkg-config
instruction and check if it says gtk+-2.0 or gtk+-3.0. It will most probably say gtk+-2.0, change to gtk+-3.0.
It also may be possible that you don't have gtk3 dev packages installed, if so, install them.
Glade XML files keep a reference to the minimum gtk version required, changing that may "solve" the issue but it won't work if you use widgets that are only available on gtk 3.
Another option is to install Glade 2 but is preferable to use the latest Gtk release as others are old.
Also check your glade menu, File > Properties and check the required Toolkit version.