Preparnig C/GTK+ development environment on Windows
In this short tutorial I'll show you two ways of setting-up C/GTK+ development environment on Windows XP (32-bit): simple way will feature Code::Blocks IDE bundle and GTK+ libraries, manual way will show you how to setup everything, well, manually;-).
I'll use compiler and binutils from MinGW project, Code::Blocks IDE and GTK+ binaries from official GTK+ page.
If you're just starting to code, simply follow the simple way and you should be able to compile your GTK+ applications in no time. Second way might be better suited for people comming from GNU/Linux, since we'll end up with functional console.
When time permits, I'll also add a section on how to distribute produced binaries, but don't hold your breath just now.
First thing we need to do is download two packages:
Install Code::Blocks IDE (default settings are just fine) and when the installation is done, extract GTK+ bundle to some folder of your choice (I usually use C:\devel\gtk
). This takes care of needed files.
Next thing to do is add GTK+'s bin folder to path. Right-click on "My Computer" icon and choose "Properties". In the box that opens, click the "Advanced" tab and then click the button "Environment Variables". Now click "New" button under user variables to create new variable. When asked about variable name, enter "PATH" and when asked about variable value, enter full path of your GTK+'s bin folder (if you followed my advice and installed GTK+ into C:\devel\gtk
, you should enter here C:\devel\gtk\bin
Last thing we need to do is edit Code::Blocks' GTK+ template (we only need to do this once). In recent versions of GTK+, gdk-pixbuf has been split from GTK+ into separate library, but Code::Blocks hasn't been updated yet. Simply start Code::Blocks and start creating new project. When "New from template" dialog appears, right-click "GTK+ project" and select "Edit this script". This will open template file in Code::Blocks editor. Now search for this line (around line 124):
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("atk-1.0"));
and add this line right after it:
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk-pixbuf-2.0"));
Save your changes and close the file. Now we're ready to test our installation.
To create new GTK+ project, click "File -> New -> Project...", select "GTK+ project" and click "Go". Now follow the wizard by filling out the requested fields. When asked about GTK+'s location, select path where you extracted the GTK+ (in this tutorial, C:\devel\gtk
is the path). When wizard ends, you'll be presented by sample GTK+ code, ready to be compiled. Click "Build -> Build and run", which should compile and run sample application.
If everything went well, you have a fully functional C/GTK+ development environment.Manual way
Again, we start by downloading some packages:
We start our installation by extracting mingw-get package to folder of your choice. I'll be using C:\devel\mingw
in this tutorial. Now open console by clicking "Start -> Run...", typing in "cmd" and pressing "Enter". Navigate to MinGW's bin folder by typing something like this (adjust to suit your installation path): cd \devel\mingw\bin
. Now we'll update package list by typing into console mingw-get update
. This will download repository information that will be used to install/update packages.
After update completes, we'll start installing MinGW components. Two components we're interested in are "gcc" (compiler and support packages) and "msys-base" (MSYS shell with some utilities like tar, grep, sed ...). We simply type mingw-get install gcc msys-base
and wait for installation to complete. Close the terminal.
Last thing we'll do with our MinGW installation is to add desktop shortcut to MSYS shell and run postinstall script when we login for the first time. Open MinGW installation directory and navigate to msys files (in my installation, this is C:\devel\mingw\msys\1.0
). Right-click msys.bat script, select "Create Shortcut" and drag created shortcut to desktop. Now launch the MSYS using newly created shortcut and type this: /postinstall/pi.sh
. Complete the wizard (when asked about path, enter something like c:/devel/mingw
). Now we're ready to compile C applications.
Installing GTK+ is started by extracting GTK+ package somewhere (I would suggest C:\devel\gtk
). Now we need to inform MSYS/MinGW about our GTK+ installation. To do this, we need to open the fstab file, located in MSYS folder (if you followed my advices, fstab is located under C:\devel\mingw\msys\1.0\etc
), and add this line to it (adjust first part to suit your selected installation path of GTK+):
Now open profile file, located in the same folder as fstab, and edit it from this
if [ $MSYSTEM == MINGW32 ]; then
if [ $MSYSTEM == MINGW32 ]; then
And we're done. From here on, you can compile GTK+ applications just like on GNU/Linux systems.