How to compile GTK +?! I read the manuals and there are connected "options" but something is missing.

pkg-config --cflags --libs gtk+-3.0

Error

 /home/hays/program/test/GTK+/main.c:3:43: error: unknown type name 'GtkEventAny' static gint delete_event_cb(GtkWidget *w, GtkEventAny *e, ^ /home/hays/program/test/GTK+/main.c: In function 'main': /home/hays/program/test/GTK+/main.c:21:24: error: 'GTK_WINDOW' undeclared (first use in this function) gtk_window_set_title(GTK_WINDOW), "Hello"); ^ /home/hays/program/test/GTK+/main.c:21:24: note: each undeclared identifier is reported only once for each function it appears in /home/hays/program/test/GTK+/main.c:21:3: error: too few arguments to function 'gtk_window_set_title' gtk_window_set_title(GTK_WINDOW), "Hello"); ^ In file included from /usr/include/gtk-3.0/gtk/gtkdialog.h:33:0, from /usr/include/gtk-3.0/gtk/gtkaboutdialog.h:30, from /usr/include/gtk-3.0/gtk/gtk.h:31, from /home/hays/program/test/GTK+/main.c:1: /usr/include/gtk-3.0/gtk/gtkwindow.h:147:12: note: declared here void gtk_window_set_title (GtkWindow *window, ^ /home/hays/program/test/GTK+/main.c:21:35: warning: left-hand operand of comma expression has no effect [-Wunused-value] gtk_window_set_title(GTK_WINDOW), "Hello"); ^ /home/hays/program/test/GTK+/main.c:21:3: warning: statement with no effect [-Wunused-value] gtk_window_set_title(GTK_WINDOW), "Hello"); ^ /home/hays/program/test/GTK+/main.c:21:44: error: expected ';' before ')' token gtk_window_set_title(GTK_WINDOW), "Hello"); ^ /home/hays/program/test/GTK+/main.c:21:44: error: expected statement before ')' token /home/hays/program/test/GTK+/main.c:24:3: warning: implicit declaration of function 'gtk_signal_connect' [-Wimplicit-function-declaration] gtk_signal_connect(GTK_OBJECT(window), "delete_event", ^ /home/hays/program/test/GTK+/main.c:24:3: warning: implicit declaration of function 'GTK_OBJECT' [-Wimplicit-function-declaration] /home/hays/program/test/GTK+/main.c:25:22: warning: implicit declaration of function 'GTK_SIGNAL_FUNC' [-Wimplicit-function-declaration] GTK_SIGNAL_FUNC(delete_event_cb), NULL); ^ /home/hays/program/test/GTK+/main.c:25:38: error: 'delete_event_cb' undeclared (first use in this function) GTK_SIGNAL_FUNC(delete_event_cb), NULL); ^ /home/hays/program/test/GTK+/main.c: In function 'button_click_cb': /home/hays/program/test/GTK+/main.c:49:3: warning: implicit declaration of function 'gtk_label_get' [-Wimplicit-function-declaration] gtk_label_get(GTK_LABEL(label), &text); ^ /home/hays/program/test/GTK+/main.c:51:3: warning: implicit declaration of function 'g_str_reverse' [-Wimplicit-function-declaration] g_str_reverse(tmp); ^ /home/hays/program/test/GTK+/main.c:52:3: warning: implicit declaration of function 'gtl_label_set_text' [-Wimplicit-function-declaration] gtl_label_set_text(GTK_LABEL(label), tmp); ^ /home/hays/program/test/GTK+/main.c: At top level: /home/hays/program/test/GTK+/main.c:35:13: warning: 'delete_event_cb' defined but not used [-Wunused-function] static gint delete_event_cb(GtkWidget *window, GdkEventAny *e, 

Code

 #include <gtk/gtk.h> static gint delete_event_cb(GtkWidget *w, GtkEventAny *e, gpointer data); static void button_click_cb(GtkWidget *w, gpointer data); int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *button; GtkWidget *label; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); button = gtk_button_new(); label = gtk_label_new("Hello, World!"); gtk_container_add(GTK_CONTAINER(button), label); gtk_container_add(GTK_CONTAINER(window), button); gtk_window_set_title(GTK_WINDOW, "Hello"); gtk_container_set_border_width(GTK_CONTAINER(button), 10); gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event_cb), NULL); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(button_click_cb), label); gtk_widget_show_all(window); gtk_main(); return 0; } static gint delete_event_cb(GtkWidget *window, GdkEventAny *e, gpointer data) { gtk_main_quit(); return FALSE; } static void button_click_cb(GtkWidget *w, gpointer data) { GtkWidget *label; gchar *text; gchar *tmp; label = GTK_WIDGET(data); gtk_label_get(GTK_LABEL(label), &text); tmp = g_strdup(text); g_str_reverse(tmp); gtl_label_set_text(GTK_LABEL(label), tmp); g_free(tmp); } 
  • one
    Actually, you should first read the errors generated by the compiler. Otherwise, why does the compiler issue them? And at least to start correct syntax errors like this gtk_window_set_title (GTK_WINDOW), "Hello"); - Vlad from Moscow
  • one
    But you see that here gtk_window_set_title (GTK_WINDOW), "Hello"); extra closure after GTK_WINDOW? And what is GTK_WINDOW? As I understand it, you should set a title for the window object. , - Vlad from Moscow
  • one
    This is a completely illiterate source of information on GTK. For example, one of the headlines looks like this: "Awareness, display and showing." What is this "awareness"? Maybe it means "Creation"? It is necessary to read the original sources, and not illiterate translations with a lot of typos. - Vlad from Moscow
  • one
    Is the original source code different from what you gave here? Those errors that are present at the link, say that the corresponding library is not connected to the project. - Vlad from Moscow
  • one
    Well, the answer is also given there, how to write the command line. - Vlad from Moscow

1 answer 1

http://www.linuxfromscratch.org/blfs/view/svn/x/gtk3.html check the dependencies and the version of the compiler.

  • one
    What does compiler version have to do with syntax errors? - Vlad from Moscow
  • Pesnite how to do it Ps packages put through synaptic -> "libgtk-3-dev" - hays
  • one
    Well, I think this way: "if the compiler gives errors, it means something is not installed, but if errors continue to go, then it is better to update the compiler, then the recommended version and not to go into the code and edit a bunch of lines." - Eugene P.
  • Look at the item: at-spi2-atk-2.16.0, gdk-pixbuf-2.31.6, and Pango-1.36.8. dpkg --list | grep <pkg> - Eugene P.
  • 2
    @Eugene P. How can a given sentence be gtk_window_set_title (GTK_WINDOW), "Hello"); one thousand and one time Explain please? - Vlad from Moscow