tags:

views:

1396

answers:

4

I have gcc installed in c:/programfiles (also set as a path variable), and i have all the necessary files for gtk from http://www.gtk.org/download-windows.html, glib,gtk,pango,atk and cairo. Although I have no clue as to how to compile a c program using gtk with the gcc compiler. How do I set everything up so that it works?. (I don't know where each zip file goes.?) basically I don't really know where start.

+8  A: 

Ok, to install and use GTK+ in Windows and use it with MinGW you may follow these steps for example. I'll try to made them the easy, don't worry:

  1. Install MinGW, as you've already done it so I wont elaborate this step.
  2. Download the GTK+ all-in-one bundle (there may be things you may not use... but this way should work).
  3. Decompress the contents of the bundle, you may do it in the same folder MinGW is installed or do it in another folder, it doesn't matter.
  4. Launch a command prompt, get to the bin directory where you extracted the bundle and run:

    pkg-config --cflags --libs gtk+-win32-2.0

  5. It will print a list of compilation flags, and libraries to link your project to. Now, copy them and create a batch file (.bat or Windows Command Script .cmd) with the following:

    set VAR=FLAGS
    start cmd

    Where VAR is a name of a variable (for example GTK) and FLAGS is the output of the previous command (pkg-config).

  6. Whenever you want to compile something that uses GTK+ double click that file, the GTK+ flags will be in VAR. You may compile this way for example:

    gcc foo.c %VAR%

Instead of a batch file, you may find more convenient to create an user environmental variable and store the flags in there, that way you will be able to compile from within a normal command prompt. I didn't describe that because the way to do it varies depending on the version of Windows you have. Generally you may find it in advanced system properties.

Once you are more confident in GTK+ programming you may not use all of the packages, or all the flags, or reorder them in a different manner, use makefiles instead of having the compilation flags and the libraries in an environmental variable, ...

But by now, this will get you started.

Also, you'll be linking dynamically to GTK+, so either the proper libraries are in the same directory of your project or are accessible from the path when you want to run it.

Xandy
Hey there thanks for the reply!, it works now, although i have to be in the same folder as the libgtk-win32.dll, how do i link this like you said?
sil3nt
When compiling you're linking dynamically to GTK+ libs, that means that your program will need those libraries in order to work. They need to be in the same folder as your program's executable file, or, they have to be in the PATH environmental variable (you have GCC installed and in the PATH variable already). If you add the "bin" folder of where you installed GTK+ to the path it'll work even if you're not in the same folder as the GTK+ libs.
Xandy
A: 

Hey thanx... nice tutorial

Imithya
A: 

Thanx ......... It really helped me........

Khan
A: 

I follow step by step but when I run file exe I get this application has failed to start because libglib-2.0-0 was not found. I don't know what to do. help please.

harunaga
post a new question or comment on the answer you found useful.
N 1.1