#GTK example 3 is outdated and uses deprecated function. What function do I use as replacement ?

20 messages · Page 1 of 1 (latest)

plain mortar
#

Hi guys, I am trying to learn GTK and example 3 uses a deprecated function called gdk_surface_create_similar_surface. However, I don't know what to use instead of this.
This is the relevant example
https://docs.gtk.org/gtk4/getting_started.html#drawing-in-response-to-input
compiled with

gcc $(pkg-config --cflags gtk4) -o example example-3 example-3.c $(pkg-config -- libs gtk4) 

This is the error I get,

example-3.c: In function ‘resize_cb’:
example-3.c:30:9: warning: ‘gdk_surface_create_similar_surface’ is deprecated [-Wdeprecated-declarations]
   30 |         surface = gdk_surface_create_similar_surface (gtk_native_get_surface (gtk_widget_get_native (widget)),      |         ^~~~~~~
In file included from /usr/include/gtk-4.0/gdk/gdkseat.h:27,
                 from /usr/include/gtk-4.0/gdk/gdkdisplay.h:30,
                 from /usr/include/gtk-4.0/gdk/gdk.h:43,
                 from /usr/include/gtk-4.0/gtk/gtk.h:30,
                 from example-3.c:1:
/usr/include/gtk-4.0/gdk/gdksurface.h:111:15: note: declared here
  111 |               gdk_surface_create_similar_surface (GdkSurface *surface,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: cannot find example-3: No such file or directory
collect2: error: ld returned 1 exit status

Gtk documentation
https://docs.gtk.org/gdk4/method.Surface.create_similar_surface.html

native lanternBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

plain mortar
#

GTK example 3 is outdated and uses deprecated function. What function do I use as replacement ?

empty mulch
#

you need to call cairo_image_surface_create yourself

plain mortar
plain mortar
#

This is my new code

#

@empty mulch

empty mulch
#

it looks like you are not passing libraries to link to a linker

plain mortar
#

Is there something more I should have added ?

empty mulch
#

remove space before libs

plain mortar
#

I can new mark this as solved

#

Unless you have anything more to add.

empty mulch
#

nope