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+.


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);

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;
  • OK, so what did you try to install?
    – terdon
    Jul 24 '17 at 13:07
  • @terdon I Don't what to download thus I didn't download anything.is there any simple command?
    – rahul
    Jul 24 '17 at 13:09
  • 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.
    – dobey
    Jul 24 '17 at 13:11
  • 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?
    – terdon
    Jul 24 '17 at 13:11
  • @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 .
    – rahul
    Jul 24 '17 at 13:15

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:


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.

  • 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.
    – rahul
    Jul 25 '17 at 4:29
  • If you don't mind waiting until October, 2017 you can try all the latest gcc-7 related packages in the 17.10 release.
    – karel
    Jul 25 '17 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.