nehemuel
nehemuel

Reputation: 71

I am trying to build a example gtk+ with C

I am trying to build my first gtk+ program write on C

I'm uses the C Gui programming book from simon long to learn and I copied the code below from the book

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

The compiler gives me the following errors:

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

I can't figure out what's wrong with my code, any idea?

Upvotes: 0

Views: 580

Answers (2)

moses ouma
moses ouma

Reputation: 11

Compile time error..

gcc -o bessewellapp bessewellapp.c -Wall pkg-config --cflags --libs gtk+-2.0 -export-dynamic

Why gtk+-2.0 no such file.

Try gtk+2.0 remove the -

Upvotes: 1

Michi
Michi

Reputation: 5307

Until you are going to provide additional information, just add the following line at the top of your file to get rid of it:

#define GTK_DISABLE_DEPRECATED

It should look like this:

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

Upvotes: 1

Related Questions