How to install latest GTK for creating C programs

16,227

You are missing a dependency required to run this program. Open the terminal and type:

sudo apt install libgtk-3-dev

Then compile the source code test.c with the following command:

gcc-5 `pkg-config --cflags gtk+-3.0` -o test test.c `pkg-config --libs gtk+-3.0`  

I used gcc-5 instead of gcc-7 in Ubuntu 16.0-4 and test.c compiled successfully. In the upcoming release of Ubuntu 17.10 the gcc-7 package will be included in the default Ubuntu repositories and it will be possible to install gcc-7 quickly and easily with apt instead of gcc-5 which I have installed with apt in 16.04. In Ubuntu 18.04 GCC 7 is the default version of GCC and gcc-8-base can be installed from the default Ubuntu 18.04 repositories.

Then run the program with this command:

./test  

and the results will be that an empty 200 × 200 pixel window with the title Window will appear which you can resize or close by clicking on the X. The window looks similar to the window in the Getting Started with GTK+ tutorial except that it has the default theme for your operating system.

Share:
16,227

Related videos on Youtube

rahul
Author by

rahul

Updated on September 18, 2022

Comments

  • rahul
    rahul almost 2 years

    I want to install latest version GTK to make small c programs. I've just finished "let us c" book which is very basic.Now I want to make GUI programs.while compiling the c program I got the following error by gcc-7 test.c

       test.c:1:10: fatal error: gtk/gtk.h: No such file or directory
       #include <gtk/gtk.h>
                 ^~~~~~~~~~~
    

    Thus I want to install latest version GTK to make simple GUI programs. I had gone to there website but there were so may files to download of which I don't know which to download. I want the latest version. so that my gtk would get upgraded when I typed apt update && apt upgrade

    I am using Xubuntu

    Here is the source code from Getting Started with GTK+.

    #include 
    
    static void
    activate (GtkApplication* app,
              gpointer        user_data)
    {
      GtkWidget *window;
    
      window = gtk_application_window_new (app);
      gtk_window_set_title (GTK_WINDOW (window), "Window");
      gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
      gtk_widget_show_all (window);
    }
    
    int
    main (int    argc,
          char **argv)
    {
      GtkApplication *app;
      int status;
    
      app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
      g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
      status = g_application_run (G_APPLICATION (app), argc, argv);
      g_object_unref (app);
    
      return status;
    }
    • terdon
      terdon almost 7 years
      OK, so what did you try to install?
    • rahul
      rahul almost 7 years
      @terdon I Don't what to download thus I didn't download anything.is there any simple command?
    • dobey
      dobey almost 7 years
      It depends on which version of GTK+ your code is written for, but as is the same with any libraries you use, you must install the development packages to compile software and link against those libraries. Ie the libgtk3.0-dev package.
    • terdon
      terdon almost 7 years
      But, surely you tried searching for the relevant package, right? You wanted an apt command, so I assume you must have tried a few, or searched for package names. So what did you find? How did it not work?
    • rahul
      rahul almost 7 years
      @terdon I've search internet and I had found so many apt commands.Like sudo apt install libgtk2.0-dev and then something config and make commands of which i don't have any idea .
    • steeldriver
      steeldriver almost 7 years
      In order for us to tell you which gtk+ version you should install, we need to know which version your C program was written for (v2 or v3)
    • rahul
      rahul almost 7 years
      @steeldriver see edited question
  • rahul
    rahul almost 7 years
    gcc 5 default version for 16.04 and it is already installed . I am using Linux mint xfce which is nothing more than Xubuntu 16.04.
  • karel
    karel almost 7 years
    If you don't mind waiting until October, 2017 you can try all the latest gcc-7 related packages in the 17.10 release.