About Me

My photo
I'm a colonist who has declared war on machines and intend to conquer them some day. You'll often find me deep in the trenches fighting off bugs and ugly defects in code. When I'm not tappity-tapping at my WMD (also, known as keyboard), you'll find me chatting with friends, reading comics or playing a PC game.

Monday, May 12, 2008

Setting up Code::Blocks on Windows

This blog post is a how-to manual on how to set up Code::Blocks for Windows along with some other libraries such SDL and GTK+.

What is Code::Blocks?
Code::Blocks is an Integrated Development Environment(IDE) for C++. This means that it provides a convenient means for programmers to type and execute their programs. You will need to provide a compiler for any IDE and there are several C/C++ compilers for the Windows environment. Since, this walk-through is newbie oriented, I will simply assume that you do not have any particular compiler in hand.

Setting up Code::Blocks on Windows.
In order to set up Code::Blocks for your Windows OS, go to http://www.codeblocks.org/downloads/5 . You will see two setup files for Windows 2000/XP/Vista. The first setup assumes that you already have a compiler to use with the IDE. The second setup, comes with the MinGW compiler for Windows. Download this setup from its Sourceforge link. Once you've downloaded the file codeblocks-8.02mingw-setup.exe, then do a full install of the IDE. I'm going to assume that the selected installation path for the IDE is C:\Program Files\CodeBlocks. The installation is pretty straight-forward and there should not be any problems. Try creating a new Console Application using the Project Wizard.

Setting up Simple DirectMedia Library for Code::Blocks on Windows.
Setting up SDL for Code::Blocks is pretty easy. Download the SDL 1.2 development bundle from the direct link here. Untar the contents of the file. You should get a folder named something like SDL-1.2.13 and within that folder you should find folders named include, lib, bin etc. Code::Blocks expects to see the file SDL.h within the include folder but as of now, if you look inside the include folder, you will find another folder named SDL. Copy all the header files from within the SDL folder one level up to the include folder and delete the folder SDL. Then, copy the entire SDL-1.2.13 folder to C:\Program Files\CodeBlocks. Now, fire up Code::Blocks and try creating a sample SDL project using the Project Wizard. When asked to specify SDL's location, just provide the path as C:\Program Files\CodeBlocks\SDL-1.2.13. Hopefully, everything should go as planned.

Setting up GTK+ for Code::Blocks on Windows.
Setting up GTK+ for Code::Blocks is even easier. Download the GTK+ development bundle from the direct link here. This zip file is a tarbomb, so neatly unzip the contents of this file to a folder named gtk+-bundle-2.12.9. Copy this entire folder to C:\Program Files\CodeBlocks. Now try creating a new GTK+ project using the Project Wizard. When asked to specify GTK's location, just provide the path as C:\Program Files\CodeBlocks\gtk+-bundle-2.12.9.

7 comments:

Raed said...

HI,,
i followed the steps for using the GTK+ , but when i build the project i get:

"test - Release" uses an invalid compiler. Skipping...
Nothing to be done.

any hints? thanks

Bernhard Jungert said...

Hi,

thats because you have to tell codeblocks where to find the toochain:

go to settings/compiler and debugger menu.
there you can specify your desired compiler (eg. gcc (=Mingw)) as default and using the tab "toolchain executables" you can enter the path to your compilers bin directory.

xuantruong said...

hello!
I compiled succesfully.
I created a gtk project file named "new".
it automaticly created a file named main.c
I delete this file and then copy my file test.c in.when I press build it sent me a message:
Compiling: test.c
WARNING: Can't read file's timestamp: C:\C_programe\new\main.c
Linking console executable: new.exe
mingw32-g++.exe: C:\C_programe\new\.objs\main.o: No such file or directory
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
so i rename my test.c to main.c
and rebuild.it succeed.but when i press run.I get:
"this application has failed to start because libgobect-2.0-0.dll was not found. re-installing the application may fix this problem".
i don't know why.
any hints? thanks

Angelo said...

Hi xuantruong,
I think the simplest fix is to simply add the 'bin' directory of your GTK installation directory to your PATH environment. Cheers.

Regele IONESCU said...

Dear Sir,
I have installed codeblocks-10.05mingw-setup.exe than followed your instructions on installing Gtk+. I added the Gtk\bin folder to the system path. When I try to compile the Gtk template I get a long list of undefined reference to...
What should I do?

I am a newbie both in programming and Gtk+.

Thank you!
Christian.

Xaos said...

Thx for the tutorial ^-^

Manuel said...

Hi, thanks for the tutorial! I'm trying to use GTK on Code::Blocks but I keep getting the following error:

fatal error: gio/gio.h: No such file or directory

Can u help me out please. I followed the directions exactly as you described them.

Thanks!