redefinition of *_get_type(void) gtk+ requried method

187 views Asked by At

As already said by the headline, I get a compile error I seem to be unable to fix:

error: redefinition of 'tinygecko_notebook_get_type'
note: previous definition of 'tinygecko_notebook_get_type' was here

Where error points to this line (the first of this codes snippet):

GType
tinygecko_notebook_get_type (void)
{
    static GType type = 0;
    if (type == 0) {
        static const GTypeInfo info = {
            sizeof (TinygeckoNotebookClass), /* size of class struct */
            NULL,   /* base_init */
            NULL,   /* base_finalize */
            (GClassInitFunc)tinygecko_notebook_class_init,   /* class_init */
            NULL,   /* class_finalize */
            NULL,   /* class_data */
            sizeof (TinygeckoNotebook),
            0,      /* n_preallocs */
            (GInstanceInitFunc)tinygecko_notebook_init   /* instance_init */
        };

        type = g_type_register_static (GTK_TYPE_NOTEBOOK, "TinygeckoNotebook", &info, 0);

    }
    return type;
}

and the note line points to the type setup

G_DEFINE_TYPE (TinygeckoNotebook, tinygecko_notebook, GTK_TYPE_NOTEBOOK);

Both snippets are located within the .c file (the note line is above the error line).

Help appreciated.. I am confused. Why should that gtk+ macro redefine a function which I have to setup for own gobject based class initalizer and finalizer (if they exist) (in this case based on GtkNotebook).

1

There are 1 answers

0
Havoc P On BEST ANSWER

G_DEFINE_TYPE is a shortcut to allow you to avoid writing the get_type function. So you don't want to use G_DEFINE_TYPE if you're implementing the get_type function by hand.

In this case I don't notice anything special in your handcoded implementation, looks like just the usual boilerplate, so you can probably just delete it and use G_DEFINE_TYPE.

There are also variants of G_DEFINE_TYPE such as G_DEFINE_TYPE_WITH_CODE, G_DEFINE_ABSTRACT_TYPE, G_DEFINE_TYPE_EXTENDED, etc. that let you deviate from pure boilerplate a bit and still avoid doing it all by hand.