unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: HiPhish <hiphish@posteo.de>
To: help-guix@gnu.org
Subject: Segfault when building GTK+ application with Meson
Date: Fri, 12 Mar 2021 21:21:39 +0100	[thread overview]
Message-ID: <4639154.31r3eYUQgx@titan> (raw)

[-- Attachment #1: Type: text/plain, Size: 2820 bytes --]

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

[-- Attachment #2: main.c --]
[-- Type: text/x-csrc, Size: 745 bytes --]

#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;
}

[-- Attachment #3: meson.build --]
[-- Type: text/x-meson, Size: 170 bytes --]

project('tutorial', 'c')
gtkdep = dependency('gtk+-3.0')
glibdep = [dependency('glib-2.0'), dependency('gobject-2.0')]
executable('demo', 'main.c', dependencies: gtkdep)

[-- Attachment #4: guix.scm --]
[-- Type: text/x-scheme, Size: 129 bytes --]

;;; Manifest file for GNU Guix environment
(specifications->manifest
  '("gcc-toolchain" "meson" "ninja" "pkg-config" "gtk+@3"))

             reply	other threads:[~2021-03-12 20:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 20:21 HiPhish [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-03-14 15:41 Segfault when building GTK+ application with Meson HiPhish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4639154.31r3eYUQgx@titan \
    --to=hiphish@posteo.de \
    --cc=help-guix@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).