'Why sources codes c++ in linux compile and does not start?

Source codes c++ gtkmm3 gtk4 linux:

#include <gtkmm.h>
#include <gtk/gtk.h>
#include <glib.h>

int main(int argc, char *argv[])
{
  auto app =
    Gtk::Application::create(argc, argv,
      "org.gtkmm.examples.base");
 
  Gtk::Window window;
  window.set_default_size(200, 200);
 
  return app->run(window);
}

I compiled them with next command in terminal:

g++ -o main main.cpp $(pkg-config --cflags gtkmm-3.0 --libs gtk3)

and they does not start and I see next errors in console (terminal) on xubuntu 21.10 xfce (xfce4-panel 4.16.3 (Xfce 4.16))

user@myPC:~$ ./main

(process:39732): GLib-GObject-WARNING **: 18:55:52.593: cannot register existing type 'GtkWidget'

(process:39732): GLib-GObject-WARNING **: 18:55:52.593: cannot add class private field to invalid type '<invalid>'

(process:39732): GLib-GObject-WARNING **: 18:55:52.593: cannot add private field to invalid (non-instantiatable) type '<invalid>'

(process:39732): GLib-GObject-CRITICAL **: 18:55:52.593: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed

(process:39732): GLib-GObject-WARNING **: 18:55:52.593: cannot register existing type 'GtkBuildable'

(process:39732): GLib-GObject-CRITICAL **: 18:55:52.593: g_type_interface_add_prerequisite: assertion 'G_TYPE_IS_INTERFACE (interface_type)' failed

(process:39732): GLib-CRITICAL **: 18:55:52.593: g_once_init_leave: assertion 'result != 0' failed

(process:39732): GLib-GObject-CRITICAL **: 18:55:52.593: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed

(process:39732): GLib-GObject-CRITICAL **: 18:55:52.593: g_type_register_static: assertion 'parent_type > 0' failed

(process:39732): GLib-GObject-WARNING **: 18:55:52.593: cannot add private field to invalid (non-instantiatable) type '<invalid>'

(process:39732): GLib-CRITICAL **: 18:55:52.593: g_once_init_leave: assertion 'result != 0' failed

(process:39732): GLib-GObject-CRITICAL **: 18:55:52.593: g_type_register_static: assertion 'parent_type > 0' failed

(process:39732): GLib-GObject-WARNING **: 18:55:52.593: cannot add private field to invalid (non-instantiatable) type '<invalid>'

Why?



Solution 1:[1]

I think you may need the package gtk3-engines-xfce or later to be installed.

sudo apt update
sudo apt install gtk3-engines-xfce

Solution 2:[2]

I don't known the reason of it. I use gtkmm on mac os and I noticed I must use "g++ -std=c++11 to compile the source, or it will failed. for your code, I think you just include <gtkmm.h> to get the program work. gtk.h and glib.h shoule be included by gtkmm.h already.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 A. Ocannaille
Solution 2 成建文