Hello everyone,
I have a weird problem: when I create a Guix environment for GTK+ development
and when I use Meson to build the project I get a segmentation fault when I
run the compiled application. I have tried with a basic C example from Meson's
website[1]. Here is the environment manifest:
(specifications->manifest
'("gcc-toolchain" "meson" "ninja" "pkg-config" "gtk+@3"))
I enable it as usual: `guix environment -m guix.scm`. Then I compile it with
Meson as usual and run it:
$ meson build
$ cd build
$ meson compile
$ ./demo
Segmentation fault
The C code, stripped down to the base basic of what it takes to trigger as
segfault:
#include <gtk/gtk.h>
#include <stdio.h>
static void activate(GtkApplication *app, gpointer user_data) {
GtkWidget *window;
GtkWidget *label;
window = gtk_application_window_new(app); /* <--- Note this */
}
int main(int argc, char **argv) {
GtkApplication *app;
app = gtk_application_new(NULL, G_APPLICATION_FLAGS_NONE);
puts("Hello");
return 0;
}
If I remove the marked line above the application terminates normally.
However, if I compile the above code with GCC it works fine:
$ gcc $(pkg-config --cflags --libs gtk+-3.0) main.c
hello
Loading the segfault into GDB reveals the following:
$ gdb ./demo core.32123
GNU gdb (GDB) 10.1
Reading symbols from ./demo...
[New LWP 32123]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/gnu/store/
fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/libthread_db.so.1".
Core was generated by `./demo'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007fe962f75f2c in call_init (l=<optimized out>, argc=argc@entry=1,
argv=argv@entry=0x7ffdd0e22cf8,
env=env@entry=0x7ffdd0e22d08) at dl-init.c:74
74 dl-init.c: No such file or directory.
It would be really nice if you could help me track down the issue because it
affects more than just GTK+, but I have not been able to narrow its source down
any further. I have attached the source code (I hope that's OK with the
rules).
To provide some background: I want to get into GTK+ development and Vala, so I
tried running the Vala language server. It has a bug which has been fixed in
the current master branch, so I tried compiling from source, but I get a
segmentation fault there as well. The only dependencies GTK+ 3 and the Vala
language server have in common are glib and json-glib, so my guess is that's
it's something inside glib. The language server does not segfault if I let
Guix build it, only if I use Guix to set up an environment and then compile it
from source myself.
[1]: https://mesonbuild.com/Tutorial.html
#include <gtk/gtk.h>
#include <stdio.h>
static void activate(GtkApplication *app, gpointer user_data) {
GtkWidget *window;
GtkWidget *label;
window = gtk_application_window_new(app);
/* label = gtk_label_new("Hello GNOME!"); */
/* gtk_container_add(GTK_CONTAINER(window), label); */
/* gtk_window_set_title(GTK_WINDOW(window), "Welcome to GNOME"); */
/* gtk_widget_show_all(window); */
}
int main(int argc, char **argv) {
GtkApplication *app;
int status;
app = gtk_application_new(NULL, G_APPLICATION_FLAGS_NONE);
puts("Hello");
/* g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); */
/* status = g_application_run(G_APPLICATION(app), argc, argv); */
/* g_object_unref(app); */
/* return status; */
return 0;
}
project('tutorial', 'c')
gtkdep = dependency('gtk+-3.0')
glibdep = [dependency('glib-2.0'), dependency('gobject-2.0')]
executable('demo', 'main.c', dependencies: gtkdep)
;;; Manifest file for GNU Guix environment
(specifications->manifest
'("gcc-toolchain" "meson" "ninja" "pkg-config" "gtk+@3"))