内置C应用程序在内置文件夹中运行,当移出内置文件夹时失败

问题描述 投票:2回答:1

我正在用C编写应用程序,并使用以下命令构建了它:

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

这很不错,很酷!除了..当我尝试将导出的文件复制到另一个文件夹(例如/ usr / bin)时,它会引发以下错误:

(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

这是我的代码。忽略介子文件。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```
c gtk building
1个回答
0
投票

我没有测试代码,但是我看到您正在使用相对路径打开Glade生成的文件。您对gtk_builder_add_from_file的所有呼叫都看起来像:

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

如果仅移动二进制文件,将无法再找到这些文件。避免这种情况的一种方法是转到reference the path in your meson file so you can use it in your code

此外,您需要进行一些适当的错误检查。请求GError **error时,使用它并检查错误而不是传递NULL,并打印GError返回的消息,它将为您节省大量时间。

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

有关更多信息,请阅读GError的工作原理(请参见“描述”部分)。

© www.soinside.com 2019 - 2024. All rights reserved.