2

I'm making an app in C and I've built it using the following command:

gcc `pkg-config --cflags gtk+-3.0` main.c -o hello `pkg-config --libs gtk+-3.0` -lX11 -rdynamic

And this works, cool! Except.. when I try to copy the exported file into another folder such as /usr/bin, then it throws the following errors:

(hello:11178): GLib-GObject-WARNING **: 16:35:55.999: invalid (NULL) pointer instance

(hello:11178): GLib-GObject-CRITICAL **: 16:35:55.999: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(hello:11178): Gtk-CRITICAL **: 16:35:55.999: gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

Here's my code. Ignore the meson file. https://github.com/JohnyTheCarrot/Paperplane

pkg-config:

-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include```

1 Answers1

0

I didn't test the code, but I see you're opening your Glade-generated files using a relative path. All your calls to gtk_builder_add_from_file look like:

gtk_builder_add_from_file (builder, "main_window.glade", NULL);

If you move only your binary, it won't be able to find these files anymore. One way to avoid that is to reference the path in your meson file so you can use it in your code.

Also, you need to do some proper error checking. Where a GError **error is requested, use it and check for errors instead of passing NULL, and print the message return by the GError, it will save you lots of time.

guint
gtk_builder_add_from_file (GtkBuilder *builder,
                           const gchar *filename,
                           GError **error);

For more information, please read how GError works (see "Description" section).

liberforce
  • 11,189
  • 37
  • 48
  • Hi! Thanks for your answer. I seem to be getting the following error in meson: fatal error: gtk/gtk.h: No such file or directory – JohnyTheCarrot Oct 03 '19 at 17:37
  • 1
    Of course. You're supposed to declare your dependencies, then use them in `executable`, not the reverse. An executable has dependencies, which makes sense. I also don't get why you're calling pkg-config in the add_project_arguments, that makes no sense. Meson is already aware of pkg-config and knows how to call it. Please read the [basic GTK+ app with Meson](https://mesonbuild.com/Tutorial.html#adding-dependencies) example on the Meson website. – liberforce Oct 04 '19 at 11:47
  • Thanks! I acknowledge that I am an idiot but I don't understand how to reference the path in my meson file with the link you've given me. Sorry. – JohnyTheCarrot Oct 04 '19 at 13:15
  • 1
    You should stop loading by file and load by GResource: https://developer.gnome.org/gio/stable/GResource.html - https://mesonbuild.com/Gnome-module.html#gnomecompile_resources – TingPing Oct 05 '19 at 00:16
  • The GResource suggestion worked, and my issue is resolved. Cheers, everyone! – JohnyTheCarrot Oct 06 '19 at 16:00
  • @JohnyTheCarrot: sorry, didn't want to sound harsh. You need to first declare your dependency (something like `gtk_dep = dependency('gtk+-3.0')`), an **then** you can pass that `gtk_dep` variable to your `executable(...)` call. This way you give to the executable the list of its dependencies, otherwise it won't find them. Currently your code only does `executable('build_test', 'main.c')` and overlooks the `dependencies` parameter of `executable(...)`. Look at the basic example I linked above. It calls `executable('demo', 'main.c', dependencies : gtkdep)`, providing the deps to the executable. – liberforce Oct 07 '19 at 12:50
  • Oh don't you worry about it, you weren't harsh! :) – JohnyTheCarrot Oct 08 '19 at 14:02