gtkmm4 sample code does not work under MacOS M1
when I want to run the sample from https://developer-old.gnome.org/gtkmm-tutorial/stable/sec-basics-simple-example.html.en on Mac, it crashed. detail information as below.
Version:
Mac: 11.6 with M1 CPU
g++
$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
gtkmm4: 4.2.0 (install from brew)
$ cat simple.cc
#include <gtkmm.h>
class MyWindow : public Gtk::Window
{
public:
MyWindow();
};
MyWindow::MyWindow()
{
set_title("Basic application");
set_default_size(200, 200);
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create("org.gtkmm.examples.base");
return app->make_window_and_run<MyWindow>(argc, argv);
$ g++ -std=c++17 simple.cc -o simple `pkg-config gtkmm-4.0 --cflags --libs`
In file included from simple.cc:1:
In file included from /opt/homebrew/Cellar/gtkmm4/4.2.0/include/gtkmm-4.0/gtkmm.h:106:
In file included from /opt/homebrew/Cellar/gtkmm4/4.2.0/include/gtkmm-4.0/gtkmm/aboutdialog.h:32:
In file included from /opt/homebrew/Cellar/gtkmm4/4.2.0/include/gtkmm-4.0/gtkmm/window.h:36:
/opt/homebrew/Cellar/gtkmm4/4.2.0/include/gtkmm-4.0/gtkmm/application.h:761:7: warning: deleting pointer to incomplete type 'Gtk::Window' may cause undefined behavior [-Wdelete-incomplete]
delete window;
^ ~~~~~~
/opt/homebrew/Cellar/gtkmm4/4.2.0/include/gtkmm-4.0/gtkmm/widget.h:76:17: note: forward declaration of 'Gtk::Window'
class GTKMM_API Window;
^
1 warning generated.
$ ./simple
Segmentation fault: 11
$ lldb ./simple
(lldb) target create "./simple"
Current executable set to '/Users/lidaobing/workspace/lidaobing/c/simple' (arm64).
(lldb) r
Process 65908 launched: '/Users/lidaobing/workspace/lidaobing/c/simple' (arm64)
2021-09-29 11:54:51.954227+0800 simple[65908:9450658] flock failed to lock list file (/var/folders/fh/5k0fl9xd06xgflnp5d90dz8m0000gn/C//com.apple.metal/16777235_322/functions.list): errno = 35
2021-09-29 11:54:51.954863+0800 simple[65908:9450658] +[MTLIOAccelDevice registerDevices]: Zero Metal services found
Process 65908 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x98)
frame #0: 0x0000000100c79da8 libgtk-4.1.dylib`gdk_macos_gl_context_real_realize + 416
libgtk-4.1.dylib`gdk_macos_gl_context_real_realize:
-> 0x100c79da8 <+416>: ldr x8, [x23, #0x98]
0x100c79dac <+420>: str x8, [sp, #0x18]
0x100c79db0 <+424>: add x2, sp, #0x10 ; =0x10
0x100c79db4 <+428>: mov w1, #0xc8
Target 0: (simple) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x98)
* frame #0: 0x0000000100c79da8 libgtk-4.1.dylib`gdk_macos_gl_context_real_realize + 416
frame #1: 0x0000000100c5eb9c libgtk-4.1.dylib`gdk_gl_context_realize + 152
frame #2: 0x0000000100c4dff4 libgtk-4.1.dylib`gdk_display_prepare_gl + 264
frame #3: 0x0000000100c6ab80 libgtk-4.1.dylib`gdk_surface_create_gl_context + 140
frame #4: 0x0000000100ca76e0 libgtk-4.1.dylib`gsk_ngl_renderer_realize + 68
frame #5: 0x0000000100c88214 libgtk-4.1.dylib`gsk_renderer_realize + 236
frame #6: 0x0000000100c888dc libgtk-4.1.dylib`gsk_renderer_new_for_surface + 272
frame #7: 0x0000000100b6706c libgtk-4.1.dylib`gtk_window_realize + 328
frame #8: 0x0000000100237f0c libgtkmm-4.0.0.dylib`Gtk::Widget_Class::realize_callback(_GtkWidget*) + 80
frame #9: 0x0000000101541fe4 libgobject-2.0.0.dylib`_g_closure_invoke_va + 320
frame #10: 0x0000000101557e10 libgobject-2.0.0.dylib`g_signal_emit_valist + 1232
frame #11: 0x00000001015585e0 libgobject-2.0.0.dylib`g_signal_emit + 28
frame #12: 0x0000000100b4c08c libgtk-4.1.dylib`gtk_widget_realize + 220
frame #13: 0x0000000100b66bc4 libgtk-4.1.dylib`gtk_window_show + 60
frame #14: 0x0000000100237d5c libgtkmm-4.0.0.dylib`Gtk::Widget_Class::show_callback(_GtkWidget*) + 80
frame #15: 0x0000000101541fe4 libgobject-2.0.0.dylib`_g_closure_invoke_va + 320
frame #16: 0x0000000101557e10 libgobject-2.0.0.dylib`g_signal_emit_valist + 1232
frame #17: 0x00000001015585e0 libgobject-2.0.0.dylib`g_signal_emit + 28
frame #18: 0x0000000100b4b9b0 libgtk-4.1.dylib`gtk_widget_show + 388
frame #19: 0x00000001000028c4 simple`int Gtk::Application::make_window_and_run<MyWindow>(int, char**)::'lambda'()::operator()() const + 80
frame #20: 0x0000000100002854 simple`decltype(std::__1::forward<MyWindow>(fp)()) std::__1::__invoke<int Gtk::Application::make_window_and_run<MyWindow>(int, char**)::'lambda'()&>(MyWindow&&) + 28
frame #21: 0x000000010000282c simple`std::__1::invoke_result<MyWindow>::type std::__1::invoke<int Gtk::Application::make_window_and_run<MyWindow>(int, char**)::'lambda'()&>(MyWindow&&) + 28
frame #22: 0x0000000100002804 simple`decltype(auto) sigc::adaptor_functor<int Gtk::Application::make_window_and_run<MyWindow>(int, char**)::'lambda'()>::operator()<>() const + 24
frame #23: 0x00000001000027e0 simple`sigc::internal::slot_call<int Gtk::Application::make_window_and_run<MyWindow>(int, char**)::'lambda'(), void>::call_it(sigc::internal::slot_rep*) + 40
frame #24: 0x0000000100836bdc libglibmm-2.68.1.dylib`Glib::SignalProxyNormal::slot0_void_callback(_GObject*, void*) + 64
frame #25: 0x0000000101541d14 libgobject-2.0.0.dylib`g_closure_invoke + 308
frame #26: 0x00000001015576f4 libgobject-2.0.0.dylib`signal_emit_unlocked_R + 2740
frame #27: 0x0000000101558270 libgobject-2.0.0.dylib`g_signal_emit_valist + 2352
frame #28: 0x00000001015585e0 libgobject-2.0.0.dylib`g_signal_emit + 28
frame #29: 0x0000000101416040 libgio-2.0.0.dylib`g_application_real_local_command_line + 1332
frame #30: 0x0000000101413e00 libgio-2.0.0.dylib`g_application_run + 408
frame #31: 0x00000001000014d0 simple`int Gtk::Application::make_window_and_run<MyWindow>(int, char**) + 204
frame #32: 0x0000000100001390 simple`main + 96
frame #33: 0x000000018b8f5430 libdyld.dylib`start + 4
(lldb)