Getting GTK+ working with glade and devc++


GTK+ turns out to be remarkably simple to use but getting it set up for devc++ was giving me some problems so I’ll give a brief tutorial.

Firstly make sure you have devc++ and Glade installed. The tool used to get all the config settings for compiling and linking doesn’t work real great in windows, it’s called pkg-config and comes with Glade. Running the following command gives the header include paths and compiler directives:

pkg-config –cflags gtk+-2.0

while the following command gives the linker options:

pkg-config –libs gtk+-2.0

The problem with these commands under windows is that the output isn’t formatted correctly, it seems the program can’t handle directories paths including spaces, this isn’t too big of a problem though.

Open up devc++ and create a new project, go to project -> project options -> directories -> include directories and add all the directories given by the first pkg-config command. On my system these are:

C:\Program Files\Gtk+\include\gtk-2.0
C:\Program Files\Gtk+\lib\gtk-2.0\include
C:\Program Files\Gtk+\include\atk-1.0
C:\Program Files\Gtk+\include\cairo
C:\Program Files\Gtk+\include\pango-1.0
C:\Program Files\Gtk+\include\glib-2.0
C:\Program Files\Gtk+\lib\glib-2.0\include
C:\Program Files\Gtk+\include\libpng12

Under library directories add the directory given by the second pkg-config command, on my system:

C:\Program Files\Gtk+\lib

Under project parameters enter -mms-bitfields in the compiler options box, we got this from the first command. Under the linker options add all the libraries listed by the second command, on my system:

-lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl

That’s it, you should be ready to go, you can test your setup with the following hello world program.

#include <gtk/gtk.h>

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

    gtk_init(&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Hello, World");
    g_signal_connect (G_OBJECT (window), "delete-event", gtk_main_quit, NULL);

    gtk_widget_show_all (window);

    return 0;

To simplify all of this I’ve created a devc++ template, simply copy the content of the zip to your devc++ templates directory, create a new project and select the template, enjoy 🙂 If the link is broken drop me a comment and I’ll fix it.


~ by s3c on 2009/12/10.

3 Responses to “Getting GTK+ working with glade and devc++”

  1. Thanks for that it works (this way).
    But why isnt it working when i put these in tools -> compiler options??

  2. Post some more info and I’ll see if i can help you out, exactly what values did you put in what fields and what versions are you running?

  3. you have no idea how much i love u right now!!!!! rly rly thank you! been sitting for hours trying to figure it out!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: