GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Aug 28, 2016 8:35 pm

All times are UTC

Post new topic Reply to topic  [ 1 post ] 

Do you find this tutorial useful?
Yes, it's great resource. 83%  83%  [ 5 ]
Somewhat, I need a bit more info. 0%  0%  [ 0 ]
No, this is utter #&%!$ 17%  17%  [ 1 ]
Total votes : 6
Author Message
 Post subject: Preparnig C/GTK+ development environment on Windows
PostPosted: Tue Jan 04, 2011 9:41 pm 
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
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.

Simple way

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/ 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+):
c:/devel/gtk /gtk

Now open profile file, located in the same folder as fstab, and edit it from this

if [ $MSYSTEM == MINGW32 ]; then
  export PATH=".:/usr/local/bin:/mingw/bin:/bin:$PATH"
  export PATH=".:/usr/local/bin:/bin:/mingw/bin:$PATH"

to this:

if [ $MSYSTEM == MINGW32 ]; then
  export PATH=".:/gtk/bin:/usr/local/bin:/mingw/bin:/bin:$PATH"
  export PATH=".:/gtk/bin:/usr/local/bin:/bin:/mingw/bin:$PATH"


And we're done. From here on, you can compile GTK+ applications just like on GNU/Linux systems.

Have fun!

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group