Code::Blocks is the Integrated Development Environment (IDE) that we will be using this semester. It is free, and runs on a PC or a Mac (and under Linux also).

Downloading Code::Blocks

If you use a PC, you need to download:

If you use a Mac, tell me and we'll get you a version.

Installing Code::Blocks under Windows

The two files you need to download are self-extracting archives. All you need to do to get them to install is to double-click on them, and the say "OK" to every question that the installer asks.

This default setup is not perfect, however. To set it up correctly, you need to:

  1. Start up Code::Blocks
  2. Go to Settings > Compiler and debugger
  3. Select Programs
  4. There is a text-entry box just under "Compiler's installation directory". Type:
    C:\Program Files\MinGW
    since that is where the default setup puts the compiler.

Now you should be ready to go.

Using Code::Blocks

Here's how I use Code::Blocks (which is not necessarily the best way).

  1. Start up Code::Blocks
  2. Go to File > New > Project
  3. Select Console Application
  4. Use the setup wizard to give the project a name (just accept the default compiler, and other configuration choices), select C++ as the language.
  5. This process will create a file main.cpp, you can either edit this file (which looks a bit different to what we have seen so far) or create a new,empty, file from the "file" menu, and add code to that.
  6. Once you are done with editing, go to Build > Compile current file
  7. Go to Build > Build
  8. Go to Build > Run
At any of the last three steps you may get errors, in which case you have to fix them and try again.

If you want to rename your program

The default program that Code::Blocks creates when you create a new project is main.cpp.

The easiest thing to do is to just edit this file.

If you want your program file to have a different name, you can do this also:

  1. Go to File > New > Empty file
  2. Save this file under whatever name you want (remembering to give the file a name that ends in .cpp)
  3. Go to Projects > Add files and add the file you just created.
  4. Go to Projects > Remove files and remove main.cpp.