Installing GTK

sudo apt-get install libgtk-3-dev

Using In Your Project

Update your makefile to use the gtk libs and cflags:

LIBS = `pkg-config --libs gtk+-3.0`

CFLAGS = `pkg-config --cflags gtk+-3.0`

Include gtk and get programming – see here.

#include <gtk/gtk.h>

Using In A NetBeans For Windows Project

Go to: Project Properties > Build > Linker > Compilation Line > Additional Options > paste in this:
         `pkg-config –cflags gtk+-3.0` `pkg-config –libs gtk+-3.0`

Note the single quote marks are correct and should be used as is!

Now you need to add all of the directories used by the gtk libraries – dull but necessary…  Use this command:

pkg-config --cflags gtk+-3.0

Which will give you an output like this:

pkg-config --cflags gtk+-3.0
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include

Convert it into a list of directories and delete any duplicates, so you end up with something like this:


Go to: Project Properties > Build > C++ Compiler > General > Include Directories > and add in each one.  For the first one you can paste the line in even though an open file dialog is shown but you may need to go back and edit it to make it right.  For subsequent ones you can simply 'duplicate' and then 'edit' to add each as a new entry.

This it, add this to your project source file and off you go.

#include <gtk/gtk.h>



We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


  1. Roark Dority

    1 year ago

    I first got started using Simon Long’s “C & GUI Programming” book which referenced Gtk 2.0 and provided a command to install that is similar to the above (sudo apt-get install libgtk-2-dev).

    I was able to use the above instead (sudo apt-get install libgtk-3-dev) and it worked great. The only struggle was the abundance of library functions that were deprecated. Still, I was able to press on, ending up with a fairly impressive application.

    Now, with the release of Gtk 4.0, I hear it is currently unavailable for Debian (Raspberry Pi Os) and the following command fails:

    sudo apt-get install libgtk-4-dev

    When I mentioned this in the Gtk forum, I pointed out that Gtk 3.0 was supported, but I was told this is likely because Gtk 3.0 had been out for nearly a decade. It was suggested I could build my own Gtk 4 compiler using the open source code, however when I attempted to do that, I kept getting additional errors. Alternatively, it was implied I might have to wait for years for Gtk 4.0 to be offered.

    Any suggestions?

    Thanks in advance for any help you can provide.


  2. Jorgen Sandberg

    1 year ago

    In the book “C & GUI Programming” is stated that this should work:

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

    When I do that using GEANY I get the error message: “No such file or directory” referring to the text within the ‘ marks.

    Please, has anyone got GTK 2 or GTK 3 to run using C and GEANY? Please, share your experience with me.

  3. Jorgen Sandberg

    1 year ago

    I am using GEANY.
    I have installed GTK 2.0 and GTK 3.0.
    I have coded a small prgram using GTK functions. The program compile, build and execute on Code::Blocks, hence my code is OK.
    Now, I use GEANY, since I want also to use pigpio that requires root permission, which is easily done in GEANY.
    I ave followed the procedure described above for NetBeans i.e. run pkg-config –cflags gtk+-2.0 and copied the output into the compile and build lines in GEANY “Build”->”Set Build Commands”->”Build”.
    The program compiles fine, but the building fails stating:
    GTK_ex_1.c:(.text+0x138): undefined reference to `gtk_init’
    for lots og GTK functions.
    Please, what do I miss to do?

    Jorgen Sandberg

  4. Jorgen Sandberg

    1 year ago

    Sorry, I had forgotten the references to the libraries.
    The libraries are added to the Build setting, by running
    pkg-config –libs gtk+-2.0
    in a terminal and copy output to the build setting.

  5. Roark Dority

    1 year ago

    Hi Jorgen,

    I hope (for your sake) this means you got things to work properly in your environment!

    I am still hoping to have Gtk 4.0 installed on the Raspberry Pi, Raspberry OS (Debian) one of these days because I find that Gtk 3.0 has many functions that have been deprecated which is rather discouraging.

    Warm Regards,


Your email address will not be published. Required fields are marked *