EECS 211
Code::Blocks Notes

Jump to Installing, Creating a project, Tips and traps, the 211 Code::Blocks FAQ.

All you really need to build a C++ application is a compiler, a Makefile to document what needs to be compiled and how, and a text editor to edit the source code. But life is a lot easier with an integrated development environments (IDE). An IDE provides a convenient interface for editing, compiling, running, and debugging code. There are many IDEs. Most are quite similar to each other, and use similar terms, such as "project" (a collection of source code files that combine to make an application) and "workspace" (a collection of projects).

On MacOS X, I recommend using XCode. It comes on the CD-ROM that came with your Macintosh, and can also be downloaded from the Apple Developer site. It's also relatively simple to set up for makefiles.

On Windows and/or Linux, I recommend Code::Blocks. Code::Blocks is a free integrated development environment (IDE) for C and C++ on Windows, Linux and MacOS X.

Code::Blocks is actually a graphical front-end to the C/C++ compiler. By default, it uses the Gnu C compiler (GCC). GCC comes with Linux and MacOS X. On Windows, GCC is available via MinGW or Cygwin. We'll use Cygwin in this class because Cygwin also provides a Unix-like shell and a nice installer.

By default, Code::Blocks uses its own internal project management system, but in this class, we are going to use Code::Blocks with custom makefiles. This takes a little bit of extra care when creating projects, but pays off in portability.

These instructions are for Windows.


You need Windows XP or Vista. If you have Vista, you will need an account with administrative privileges.

You need Cygwin with the GNU debugger and CppUnit. See these installation instructions for setting up Cygwin. Do this before installing Code::Blocks.

Download and test the example Makefile. You need the directory and files from that test to do these instructions.

Download and install Code::Blocks

Downloading and installing Code::Blocks takes just a few steps.

This is a good time to quit and save your workspace so far. When you exit Code::Blocks, it will ask where you want save the workspace file. Put it in the top level of your projects directory. Give it a short name, like eecs211. The file will be saved with the extension workspace. Later on, just double-click this file to start Code::Blocks.

Creating a Console Project

A console project is a program that does all input and output through a console window, such as Window's Command Console or MacOS X's Terminal window. These are the simplest programs to write, but still useful, especially in the Unix world.

To create and test an example project using CppUnit,

Start Code::Blocks by double-clicking the workspace file you created.

Code::Blocks will open its front page. On that page, click Create a new project.

XCode::Blocks front page

A dialog box will appear with options for many different kinds of projects.

Click on Empty project and click Go.

Code::Blocks select console

The project wizard will introduce itself. Click Next >.

The wizard will ask which programming language you want to use. Pick C++ and click Next >.

Code::Blocks select language

The wizard will ask what you want to call your project and where you want to put it.

Click ... and use the file dialog box that appears to find and select your course projects directory.

Then enter the project name. This must match the value of PROJ in the Makefile. For the example project, therefore, use example.

Click Next > when done.

Code::Blocks project title box

Code::Blocks will ask what targets you want to build. Since you'll be using a Makefile with a target called all,

Click Finish when done.

Code::Blocks target options box

Now tell Code::Blocks which files are part of your project.

Select Add files... from the Project menu.

Select the two source files in the example directory.

Afterward, click on the plus-signs in the project window, to see the files grouped under Sources, Headers and Others.

Code::Blocks example project files

Now tell Code::Blocks how to call the Makefile

Select Properties... from the Project menu.

Check the box for This is a custom Makefile..

Click OK to save this setting.

Code::Blocks custom makefile

Select Build Options... from the Project menu.

Use the arrow buttons to scroll the tabs until you see the "Make" commands.

Select "Make" commands and change the field for Clean project/target to be $make -f $makefile clean.

Click OK twice.

Code::Blocks make commands

Now test your project.

Select Build and Run from the Build menu.

If all is set up correctly, the project should compile your project, creating the application example.exe. It then runs the application in a console window.

The console output should look like the output you saw when you ran the executable directly in a console window.

To close the console window and return to your project, press any key while the console window is active

Exit Code::Blocks to save your work.

Code::Blocks make commands

Tips and Traps

Learn the shorcuts. This is a general tip for any development tool. After you've used your IDE a bit, learn to use the keyboard shortcuts for compiling and running and so on. This will speed up coding and testing a lot.

Don't rename code files in the Finder. This is a general tip for any development tool. Don't rename or delete files behind its back. The IDE can get very confused. Most IDEs provide their own commands for renaming and removing files, that rename or remove the file and also update the IDE's internal records.

Start Code::Blocks by double-clicking your workspace file. If you keep one workspace file with all your class projects, you'll have easy access to old code, and Code::Blocks will remember many (though not all) of your settings when you create a new project.

Comments? comment icon Contact the Prof!

Valid HTML 4.01 Transitional