Reputation: 105
I am trying to get setup using GTK3+ and Glade. Unfortunately the most basic setup I can find online is sefaulting. In Glade I just created a basic window with the ID window_main
. I'm not sure how this isn't working.
bytebowl.c
#include <gtk/gtk.h>
int main(int argc, char* argv[])
{
GtkBuilder *builder;
GtkWidget *window, *label;
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "glade/hello.glade", NULL);
window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
g_object_unref(builder);
gtk_widget_show(window);
gtk_main();
return 0;
}
hello.glade
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="window_main">
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
</object>
</interface>
[michael@thinkpad ~/Code/ByteBowl]$ ./bytebowl
(process:8290): Gtk-CRITICAL **: 15:01:02.191: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
(process:8290): Gtk-CRITICAL **: 15:01:02.195: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
(process:8290): Gtk-CRITICAL **: 15:01:02.195: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
zsh: segmentation fault (core dumped) ./bytebowl
the Makefile...
CC=clang
CFLAGS=`pkg-config --cflags gtk+-3.0`
LFLAGS=`pkg-config --libs gtk+-3.0`
all: bytebowl
bytebowl:
$(CC) $(CFLAGS) -o bytebowl src/bytebowl.c $(LFLAGS)
Here is the dmesg output...
[michael@thinkpad ~/Code/ByteBowl]$ sudo dmesg
[...snip...]
[16452.137217] bytebowl[8256]: segfault at 18 ip 00007f18a6591e8c sp 00007fff910ef2e0 error 4 in libgtk-3.so.0.2404.25[7f18a6506000+382000]
[16452.137249] Code: ff 0f 1f 44 00 00 48 83 c4 08 5b 5d c3 90 48 8b 7f 10 48 85 ff 74 07 e9 42 ed ff ff 66 90 48 83 ec 08 48 89 d7 e8 14 31 18 00 <48> 8b 40 18 48 8b 78 10 67 e8 06 ac 09 00 48 83 c4 08 48 89 c7 e9
[16452.137393] audit: type=1701 audit(1623265257.250:356): auid=1000 uid=1000 gid=1000 ses=1 pid=8256 comm="bytebowl" exe="/home/michael/Code/ByteBowl/bytebowl" sig=11 res=1
Upvotes: 1
Views: 209
Reputation: 3696
You need to call gtk_init()
before any other functions from Gtk.
Additionally, gtk_builder_get_object()
does not pass ownership of the widget to the caller, so calling g_object_unref()
on the builder where you do is probably not a good idea.
Upvotes: 2