Sunday, 22 April 2012

Installing GTK+ on Windows 7 and MinGW

GTK+ is a GUI library for C and a bunch of other languages. Recently, I had the "pleasure" of installing this on Windows 7. Follow these steps and you'll be compiling GTK C programs in no time.

Download the GTK+ bundle for windows (32 or 64bit), I used 32 bit because my MinGW is 32bit.

Install in a simple directory like C:\opt\ or F:\opt\

Go to your windows environment variables on your computer and add GTK's bin directory to the PATH variable. eg. C:\opt\bin

Execute both of these commands on the command line:
pkg-config --cflags gtk+-2.0
pkg-config --libs gtk+-2.0

If the above commands fail to produce outputs than your install is bad, you need to reinstall or check your PATH variable.

Next, run package config and store the result into a file using the output direction '>'
Example:
pkg-config --cflags --libs gtk+-2.0 > flags.txt

Copy the contents of flags.txt into your makefile or use on the command line

The compile line should look like this:

gcc -o main main.c -mms-bitfields -IF:/opt/include/gtk-2.0 -IF:/opt/lib/gtk-2.0/include -IF:/opt/include/atk-1.0 -IF:/opt/include/cairo -IF:/opt/include/gdk-pixbuf-2.0 -IF:/opt/include/pango-1.0 -IF:/opt/include/glib-2.0 -IF:/opt/lib/glib-2.0/include -IF:/opt/include -IF:/opt/include/freetype2 -IF:/opt/include/libpng14  -LF:/opt/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl

GTK should now be setup for windows, happy coding.

P.S. When compiling object files using gcc -c you only need to link in the cflags files.
Using the method above, but only with: pkg-config --cflags gtk+-2.0

3 comments:

  1. Thanks. This helped a lot!

    ReplyDelete
  2. Hi, I tried using your step. It was fine at first but stuck at the gcc...the command prompt stated gcc is not recognize as an internal or external command. What should I do next? Thanks.

    ReplyDelete
    Replies
    1. Hi, you haven't put the location of the gcc binary into the system PATH variable.

      http://www.mingw.org/wiki/Getting_Started

      Read under the heading: Environment Settings

      Delete