How to build GUI application in C language using GTK+?

6,958

If you have installed the libgtk2.0-dev package in the normal way from the repository, then you can build your application with gcc, using pkg-config to set the appropriate include and library directives e.g.

gcc -o myapp myapp.c `pkg-config --cflags --libs gtk+-2.0`

For more information see the GTK+ 2.0 Tutorial at the Gnome Developer Center

Share:
6,958

Related videos on Youtube

osama
Author by

osama

Updated on September 18, 2022

Comments

  • osama
    osama over 1 year

    I have written code in C language using GTK. This code gives a window with 2 buttons, but I do not know how to make the standalone GUI application from this code.

    Please explain to me step by step and in detail.

    #include<gtk/gtk.h>
    void static call(GtkWidget *widget,gpointer data)
    {
        g_print("%s \n",(gchar*) data);
    }
    
    int main(int agrc, char *agrv[])
    {
        gtk_init(&agrc,&agrv);
        GtkWidget *window,*button,*vbox;
        window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
        g_signal_connect(window,"delete-event",G_CALLBACK(gtk_main_quit),NULL);
        gtk_window_set_title(GTK_WINDOW(window),"two button");
    
        vbox=gtk_vbox_new(0,0);
        button=gtk_button_new_with_label("button 1");
        g_signal_connect(button,"clicked",G_CALLBACK(call),(gpointer) "BUTTON 1");
        gtk_box_pack_start(GTK_BOX(vbox),button,0,0,0);
        button=gtk_button_new_with_label("button 2");
        g_signal_connect(button,"clicked",G_CALLBACK(call),(gpointer) "BUTTON 2");
        gtk_box_pack_start(GTK_BOX(vbox),button,0,0,0);
        button=gtk_button_new_with_label("Close");
        g_signal_connect(button,"clicked",G_CALLBACK(call),(gpointer) "BUTTON 2");
        gtk_box_pack_start(GTK_BOX(vbox),button,0,0,0);
        gtk_container_set_border_width(GTK_CONTAINER(window),10);
        gtk_container_add(GTK_CONTAINER(window),vbox); 
        gtk_widget_show_all(window);
        gtk_main();
        return (0);
    }
    
  • osama
    osama over 10 years
    this command works fine and creates .exe file for simple c code without any #include<gtk/gtk.h in the c code i586-mingw32msvc-gcc code.c -o code but when i try to compile c code with #include<gtk/gtk.h using the following command it gives me error i586-mingw32msvc-gcc code.c -o code pkg-config --cflags --libs gtk+-2.0