What could be wrong: GLib-GObject-WARNING **: cannot register existing type 'PangoCairoFont'

3.6k views Asked by At

I spent many weeks trying to get gtk+ 3.22 to build on Visual Studio 2015. Finally I got it built but the small GUI program failed to initialize gtk. The error is shown as below:

gtk+_gtk_test.exe:15980): Gtk-WARNING **: Could not find the icon 'window-minimize-symbolic-ltr'. The 'hicolor' theme
was not found either, perhaps you need to install it.
You can get a copy from:
        http://icon-theme.freedesktop.org/releases

(gtk+_gtk_test.exe:15980): GLib-GObject-WARNING **: cannot register existing type 'PangoCairoFont'

(gtk+_gtk_test.exe:15980): GLib-GObject-CRITICAL **: g_type_interface_add_prerequisite: assertion 'G_TYPE_IS_INTERFACE (interface_type)' failed

(gtk+_gtk_test.exe:15980): Glib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed

The first warning exists because the executable cannot locate the icon files. I have already figured out how to fix this. However, I am unable to get the second Warning fixed. This is my first gtk+ project. When I debug the code, it seems that PangoCairoFont type failed because of the existence of PangoCairoWin32Font type.

What could be wrong here? Appreciate your advice.

Source code of the program:

#include <gtk/gtk.h>

void hello(GtkWidget *widget, gpointer data)
{
    g_print("Hello, World\n");
}

gint delete_event(GtkWidget *widget, GdkEvent event, gpointer data)
{
    /* when this fucntion returns FALSE, the delete-event 
       signal becomes a destroy signal*/
    return FALSE;
}

void end_program(GtkWidget *widget, gpointer data)
{
    /* End the main loop */
    gtk_main_quit();
}

int main(int argc, char **argv)
{
    GtkWindow *window;
    GtkButton *button;

    /* initialize Gtk+ */
    gtk_init(&argc, &argv);

    /* create window, set default height and width to 200px */
    window = g_object_new(GTK_TYPE_WINDOW,
        "default-height", 200,
        "default-width", 200,
        "border-width", 12,
        "title", "GtkHello",
        NULL);

    /* add signal handlers for window */
    g_signal_connect(window, "delete-event", G_CALLBACK(delete_event),
        NULL);

    g_signal_connect(window,
        "destroy", G_CALLBACK(end_program),
        NULL);

    /* create button */
    button = g_object_new(GTK_TYPE_BUTTON,
        "label", "_Hello, World!\nClick here.",
        "use-underline", TRUE,
        NULL);

    g_signal_connect(button,
        "clicked", G_CALLBACK(hello),
        NULL);

    g_signal_connect_swapped(button,
        "clicked", G_CALLBACK(gtk_widget_destroy),
        window);

    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(button));

    gtk_widget_show_all(GTK_WIDGET(window));

    /* start main loop */
    gtk_main();

    return 0;
}
1

There are 1 answers

1
cuteCAT On BEST ANSWER

I figured out. I mistakenly built pangocairo module into a static lib instead of DLL. This lib is further linked into different DLLs so the global variable has several copies, which caused the problem.