I am prototyping a basic app but consecutive GTK errors prevent me from compiling it. Which commands can I use to ignore those error and force a compile C?


Greetings fellow humans. Human fellas.

I’m roughly coding a basic GTK app using Glade and C(GTK3).

I have an issue with my code not compiling due to too many consecutive warnings.

gtk_button_set_image(GTK_CONTAINER(button0), imageWhite);

When this line is used by itself, compiling it with
gcc -Wno-format -o test2_bin main.c -Wno-deprecated-declarations -Wno-format-security -lm pkg-config --cflags --libs gtk±3.0 -export-dynamic -rdynamic

Causes warnings like

/usr/include/glib-2.0/gobject/gtype.h:2297:6: warning: passing argument 1 of ‘gtk_button_set_image’ from incompatible pointer type [-Wincompatible-pointer-types]
 2297 |     ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
/usr/include/glib-2.0/gobject/gtype.h:484:66: note: in expansion of macro ‘_G_TYPE_CIC’
  484 | #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type)    (_G_TYPE_CIC ((instance), (g_type), c_type))
      |                                                                  ^~~~~~~~~~~
/usr/include/gtk-3.0/gtk/gtkcontainer.h:38:42: note: in expansion of macro ‘G_TYPE_CHECK_INSTANCE_CAST’
   38 | #define GTK_CONTAINER(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CONTAINER, GtkContainer))
      |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:669:24: note: in expansion of macro ‘GTK_CONTAINER’
  669 |   gtk_button_set_image(GTK_CONTAINER(button1), NULL);
      |                        ^~~~~~~~~~~~~
In file included from /usr/include/gtk-3.0/gtk/gtk.h:54,
                 from main.c:6:
/usr/include/gtk-3.0/gtk/gtkbutton.h:151:70: note: expected ‘GtkButton *’ {aka ‘struct _GtkButton *’} but argument is of type ‘GtkContainer *’ {aka ‘struct _GtkContainer *’}
  151 | void                  gtk_button_set_image          (GtkButton      *button,
      |                                                      ~~~~~~~~~~~~~~~~^~~~~~

And the application compiles successfully and works as intended.

However, if I use the above multiple times, the same warning pops up multiple times and the application fails to compile.

This is just a rough implementation so I just want to application to compile regardless of how many warning messages GTK throws. Is there an argument I could add to the GCC command that would allow me to do this? Thanks!

You should fix your code instead.

The gtk_button_set_image() function takes a GtkButton* as the first argument, so you should use GTK_BUTTON(button1), not GTK_CONTAINER(button1).

Learn to listen to what the compiler is telling you. It’ll save you time down the line.


This was the first fix I attempted and it didn’t work. Now it does. what is wrong with me

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