I'm trying to install the GTK development environment on Ubuntu, and having difficulty simply get it installed.

Basically, my goal is to simply compile a C file which includes the header file <gtk/gtk.h>, so I can start tinkering around:

#include <gtk/gtk.h>

int main() { }

So, this answer says you can simply apt-get install gnome-core-devel build-essential to get the development environment installed. Okay, so I tried that and when I try to compile the above code, I get, the compiler complains it can't find the file gtk/gtk.h

So, I add /usr/include/gtk-2.0/ to the Path and compile again. Now it complains that it can't find another file /gio/gio.h.

This file didn't even exist on my system, so after googling around for gio.h, and apt-getting other libraries, I managed to install it. I tried compiling again, this time the compiler can't find /usr/include/glib-2.0/glib/gtypes.h.

At this point, I'm thinking it can't possibly be this difficult to simply install something like GTK development enviroment, which is a fairly popular package. I thought maybe something was wrong with my system, so I tried this on a different install of Ubuntu, and ran into the same issues.

So, what exact packages are necessary to install GTK? And will I need to manually configure my include path, or is that supposed to happen automatically?


There are two versions of GTK+, gtk+2 and gtk+3. You should choose or at least prefer gtk+3, as the transition has began some time ago.

There are some examples for gtk3 here: http://developer.gnome.org/gtk3/3.2/gtk-getting-started.html

#include <gtk/gtk.h>

main (int   argc,
char *argv[])
  GtkWidget *window;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  gtk_widget_show (window);

  gtk_main ();

  return 0;

To find which package provides a file, head to http://packages.ubuntu.com and scroll down to "Search the contents of packages". Enter the file name as keyword and search for the file.

gtk.h is provided by two packages:

/usr/include/gtk-2.0/gtk/gtk.h libgtk2.0-dev

/usr/include/gtk-3.0/gtk/gtk.h libgtk-3-dev

Install libgtk-3-dev for gtk+3.

Finally, mind the command you execute (see the examples from the link I mentioned above):

gcc `pkg-config --cflags gtk+-3.0` -o window-default window-default.c `pkg-config --libs gtk+-3.0`

Keep the order of the arguments the same. You may want to add -Wall to show any errors that need to be fixed:

gcc `pkg-config --cflags gtk+-3.0` -o window-default window-default.c -Wall `pkg-config --libs gtk+-3.0`

If you're still facing problems, show/attach the command you use and the output provided to your question above.

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.