compiler-errorsgtk

compiling error gtk2 source with gtk3: ‘GtkStyle’ {aka ‘struct _GtkStyle’} has no member named ‘font’


Trying to compile emelfm-0.9.2 with gtk3 (I'm not a coder just a linux enthusiast). Modified Makefile.common and now many of the .c files compiled OK. However, the window.c component stopped with the error in question:

window.c:257:10: error: ‘GtkStyle’ {aka ‘struct _GtkStyle’} has no member named ‘font’
  257 |     style->font = app.output_font;
      |          ^~
make: *** [Makefile:17: window.o] Error 1

The Makefile.common original version is:

PREFIX = /usr/local
BIN_DIR = $(PREFIX)/bin
LOCALEDIR = $(PREFIX)/share/locale
PLUGINS_DIR = $(PREFIX)/share/emelfm/plugins
DOC_DIR = $(PREFIX)/share/emelfm/docs

NLS = -DENABLE_NLS
GTK_INCLUDE = `gtk-config --cflags`
GTK_LIB = `gtk-config --libs`
GLIB_LIB = `glib-config --libs gthread`
CC = gcc -O2 -Wall

The modified section is:

NLS = -DENABLE_NLS
GTK_INCLUDE = `pkg-config --cflags gtk+-2.0`
GTK_LIB = `pkg-config --libs gtk+-2.0`

I modified it because "gtk-config" or "glib-config" command is now "pkg-config". As a result the "make" process started OK but could not finish because of the error in the window.c component.

Is there an easy fix to this?


Solution

  • Easy fix for non-coder? No, but doable. Let's begin with:

    1. You want to build with gtk3 but you are using pkg-config --cflags gtk+-2.0, where gtk+-2.0 uses... you guess it! Gtk2. If you want to build gtk3, you must use gtk+-3.0.
    2. In Gtk3 universe, GtkStyle is deprecated, see the docs:

    In GTK+ 3.0, GtkStyle has been deprecated and replaced by GtkStyleContext

    1. So, you have to dive into the sources of the app and make the changes need it to convert the gtk2 code in gtk3. If you really want to continue, you must read the migration information and changes.