Undefined function in new GTK+3 project in GNOME Builder


I’ve started a new project in GNOME Builder and it has a basic template with a Hello World GUI program.

Let’s say the application name is “foobar”.

It defines a macro:

#define FOOBAR_TYPE_APPLICATION (foobar_application_get_type())

and this gets used to construct a new object:

g_object_new (FOOBAR_TYPE_APPLICATION, “application-id”, application_id, “flags”, flags, NULL);

However, foobar_application_get_type() is not declared or defined anywhere. Yet everything compiles and runs fine.

What is going on here?


The get_type() function for a type is defined by the G_DEFINE_TYPE macro.

For more information, you want to read the GObject tutorial.

Ok, but this isn’t the get_type() function… is it?

It’s a function called foobar_application_get_type().

And there are no calls to anything before hand, it is top-level with only the gtk.h header included above it.

I used get_type() as a shorthand, not as the literal function name.

The G_DEFINE_TYPE macro will define a *_get_type() function for the given type you’re defining, e.g.

G_DEFINE_TYPE (FooApplication, foo_application, GTK_TYPE_APPLICATION)`

Will define the foo_application_get_type() function.

You really need to read the GObject tutorial I linked you.

You aren’t wrong! Thanks for the link.

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