我正在尝试用 C 构建一个示例 gtk+

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

我正在尝试构建我的第一个用 C 编写的 gtk+ 程序

我使用 simon long 的 C Gui 编程书来学习,我从书中复制了下面的代码

#include <stdio.h>
#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
    gtk_init (&argc, &argv);
    GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_show (win);
    gtk_main ();
    return 0;
    
}

编译器给我以下错误:

gcc -o bessewellapp bessewellapp.c -Wall `pkg-config --cflags --libs gtk+-2.0` -export-dynamic
In file included from /usr/include/gtk-2.0/gtk/gtkobject.h:37,
                 from /usr/include/gtk-2.0/gtk/gtkwidget.h:36,
                 from /usr/include/gtk-2.0/gtk/gtkcontainer.h:35,
                 from /usr/include/gtk-2.0/gtk/gtkbin.h:35,
                 from /usr/include/gtk-2.0/gtk/gtkwindow.h:36,
                 from /usr/include/gtk-2.0/gtk/gtkdialog.h:35,
                 from /usr/include/gtk-2.0/gtk/gtkaboutdialog.h:32,
                 from /usr/include/gtk-2.0/gtk/gtk.h:33,
                 from bessewellapp.c:2:
/usr/include/gtk-2.0/gtk/gtktypeutils.h:236:1: warning: ‘GTypeDebugFlags’ is deprecated [-Wdeprecated-declarations]
  236 | void            gtk_type_init   (GTypeDebugFlags    debug_flags);
      | ^~~~
In file included from /usr/include/glib-2.0/gobject/gobject.h:24,
                 from /usr/include/glib-2.0/gobject/gbinding.h:29,
                 from /usr/include/glib-2.0/glib-object.h:22,
                 from /usr/include/glib-2.0/gio/gioenums.h:28,
                 from /usr/include/glib-2.0/gio/giotypes.h:28,
                 from /usr/include/glib-2.0/gio/gio.h:26,
                 from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
                 from /usr/include/gtk-2.0/gdk/gdk.h:32,
                 from /usr/include/gtk-2.0/gtk/gtk.h:32,
                 from bessewellapp.c:2:
/usr/include/glib-2.0/gobject/gtype.h:679:1: note: declared here
  679 | {
      | ^
In file included from /usr/include/gtk-2.0/gtk/gtktoolitem.h:31,
                 from /usr/include/gtk-2.0/gtk/gtktoolbutton.h:30,
                 from /usr/include/gtk-2.0/gtk/gtkmenutoolbutton.h:30,
                 from /usr/include/gtk-2.0/gtk/gtk.h:126,
                 from bessewellapp.c:2:
/usr/include/gtk-2.0/gtk/gtktooltips.h:73:3: warning: ‘GTimeVal’ is deprecated: Use 'GDateTime' instead [-Wdeprecated-declarations]
   73 |   GTimeVal last_popdown;
      |   ^~~~~~~~
In file included from /usr/include/glib-2.0/glib/galloca.h:32,
                 from /usr/include/glib-2.0/glib.h:30,
                 from /usr/include/glib-2.0/gobject/gbinding.h:28,
                 from /usr/include/glib-2.0/glib-object.h:22,
                 from /usr/include/glib-2.0/gio/gioenums.h:28,
                 from /usr/include/glib-2.0/gio/giotypes.h:28,
                 from /usr/include/glib-2.0/gio/gio.h:26,
                 from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
                 from /usr/include/gtk-2.0/gdk/gdk.h:32,
                 from /usr/include/gtk-2.0/gtk/gtk.h:32,
                 from bessewellapp.c:2:
/usr/include/glib-2.0/glib/gtypes.h:547:8: note: declared here
  547 | struct _GTimeVal

我不知道我的代码出了什么问题,有什么想法吗?

c gtk gtk3 gtk2
2个回答
1
投票

在您要提供其他信息之前,只需在文件顶部添加以下行即可将其删除:

#define GTK_DISABLE_DEPRECATED

它应该看起来像这样:

#define GTK_DISABLE_DEPRECATED

#include <gtk/gtk.h>

int main ( int argc, char *argv[] )
{
    gtk_init ( &argc, &argv );

    /// ***
    GtkWidget *win = gtk_window_new ( GTK_WINDOW_TOPLEVEL );

    /// ***
    gtk_widget_show ( win );

    /// ***
    gtk_main ();
}

0
投票

编译时错误..

gcc -o bessewellapp bessewellapp.c -Wall

pkg-config --cflags --libs gtk+-2.0
-导出动态

为什么gtk+-2.0没有这个文件。

尝试gtk+2.0删除-

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