1

I'm trying to implement in my GTK 2.0 application the advice from question How to create a cairo_t on a Gtk 2 window, and I am perplexed by the result. The error output is

planes_view.c: In function ‘draw_lines_planes’:
planes_view.c:145:33: warning: passing argument 1 of ‘gdk_cairo_create’ from incompatible pointer type [enabled by default]
   cr = gdk_cairo_create((struct GdkDrawable *)(view->drawing_area));
                             ^
In file included from /usr/include/gtk-2.0/gdk/gdk.h:33:0,
                 from /usr/include/gtk-2.0/gtk/gtk.h:32,
                 from planes_view.h:35,
                 from planes_view.c:34:
/usr/include/gtk-2.0/gdk/gdkcairo.h:33:10: note: expected ‘struct GdkDrawable *’ but argument is of type ‘struct GdkDrawable *’
 cairo_t *gdk_cairo_create            (GdkDrawable        *drawable);
         ^

Note that the two conflicting types are identical. How can this be? Perhaps two types with the same name? Even if so, I need to know how to do this right.

The offending line was originally

cr = gdk_cairo_create(view->drawing_area);

And the complaint was that the drawing area's declared type is GtkWidget *, so I tried a normal typecast thus:

cr = gdk_cairo_create((struct GdkDrawable *)(view->drawing_area));

with the results shown above.

Community
  • 1
  • 1
4dummies
  • 759
  • 2
  • 9
  • 22
  • Can you cut it down to a minimal compilable example? (My gut instinct tells me that you've got incompatible defs of what the struct is, but I don't think that's quite the error you'd see.) – tabstop Jan 15 '14 at 15:49
  • try to remove the keyword "struct". I guess GdkDrawable is already a typedef. – robin.koch Jan 15 '14 at 16:12
  • You can't just cast things to something they're not (GtkWidget is not a GdkDrawable). The GdkDrawable you want is probably `view->drawing_area->window`, but why not do what I did in the original answer: `widget->window` (assuming the first argument of the expose handler is called widget)? ... actually now that I think about it: `gtk_widget_get_window (widget)` would be the best way. – Jussi Kukkonen Jan 16 '14 at 09:29

2 Answers2

1

Trust the compiler. A struct GdkDrawable * is not the same as a GdkDrawable *. GdkDrawable is already a typedef to a struct:

typedef struct _GdkDrawable GdkDrawable;

And as jku said, you're messing things up. gdk_cairo_create expects a GdkDrawable, and you're trying to feed it a GtkWidget. Your GdkDrawable is the GdkWindow that is stored inside the GtkWidget (the window member), that you can access using gtk_widget_get_window.

liberforce
  • 11,189
  • 37
  • 48
0

I would say you have incompatible definitions of the symbol, or that you somehow compile this symbol several times. Check the visibility of the symbol.

Olotiar
  • 3,225
  • 1
  • 18
  • 37