Code::Blocks 16.01

You can use the Code::Blocks C/C++ IDE with many MousePaw Media projects. While this isn’t our officially recommended IDE, many of our staff members use it.

Installing Code::Blocks

Installing Code::Blocks 16.01 on Linux

Ubuntu 16.04 and later offer Code::Blocks v16.01 in the main repositories.

On any supported Ubuntu (or Debian) system, run...

$ sudo apt update
$ sudo apt install codeblocks codeblocks-contrib

That will install (or update) both codeblocks itself, and the plugins (of which we use quite a few).

Note

Many Ubuntu systems older than 16.04 can still install v16.01 by using the PPA ppa:damien-moore/codeblocks-stable.

If you want the newer release, 17.12, you’ll need to download it from http://www.codeblocks.org/downloads/26#linux.

Installing Code::Blocks 16.01 on Mac

The last version of Code::Blocks available for Mac was 13.12, which is considerably outdated. If you still want to use it, you can download it from http://www.codeblocks.org/downloads/26#mac

Installing Code::Blocks 16.01 on Windows

You can download the official installer for Code::Blocks v16.01 from https://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/. This is the version that we use at MousePaw Media, and which these instructions are based on.

You’ll notice there are several options there.

  • For most situations, you should use codeblocks-17.12-setup.exe.
  • If you would like to setup MinGW at the same time as Code::Blocks (assuming you have NOT already set it up!), you can use codeblocks-17.12mingw-setup.exe.

If you would prefer to install the latest version of Code::Blocks (v17.12), you can download it from http://www.codeblocks.org/downloads/26#windows. However, these instructions may not apply, and our projects may not necessarily work correctly in that version. Use at your own risk.

Note

The Code::Blocks projects we include in our repositories are all configured to use UNIX Makefiles. If you’re attempting to compile from Code::Blocks on Windows, you may need to figure some things out yourself.

Trimming Down on Plugins

With all of the plugins installed by default, Code::Blocks can be utterly overwhelming. To make life easier, we’re going to disable all but the most essential plugins. Later on, you can re-enable those additional plugins that you are interested in.

On the top menu, go to Plugins ‣ Manage Plugins.... Select all of the plugins by clicking the first, scrolling to the bottom, holding down Shift, and clicking the last. Then, click Disable.

Now we will re-enable the plugins we most commonly use.

  • Class wizard
  • Code completion
  • Code profiler
  • Code snippets
  • Code statistics
  • Compiler
  • CppCheck
  • Debugger
  • EditorTweaks
  • Files extension handler
  • Foreign projects importer
  • HexEditor
  • OccurrencesHighlighting
  • Open files list
  • Project options manipulator
  • Regular expressions testbed
  • Scripted wizard
  • Source Exporter
  • Source code formatter (AStyle)
  • Todo List

Now click OK.

Important

In between changes, save the workspace by clicking File ‣ Save workspace.

Hint

If you ever cannot see the OK button on a window, maximize the window. It will be at the bottom.

Configuring the Environment

Code::Blocks is highly customizable. We’re going to make some changes to the Environment, but while we do that, take some time and explore the other settings there. Fine-tune things to your liking!

Go to Settings ‣ Environment.

Setting Your Terminal

I don’t know about you, but I never did like the default Terminal in Linux. There are a number of other fantastic terminal emulators on Linux. Below is a table of some of the most common, the command to install it, and the launch command. That launch command belongs in this Environment window, under Terminal to launch console programs:.

Just for reference, Terminator is my personal favorite.

Warning

Guake is an awesome terminal, but I don’t recommend it for this.

Important

Put a trailing space at the end of each of the Launch Commands! If you omit it, things will not work.

Terminal Name Install Command Launch Command
Gnome Terminal sudo apt install gnome-terminal gnome-terminal -t $TITLE -x
Konsole sudo apt install konsole konsole -e
Terminator sudo apt install terminator terminator -T $TITLE -x
Terminology sudo apt install terminology terminology -M -T $TITLE -e
XCFE 4 Terminal sudo apt install xfce4-terminal xfce4-terminal -T $TITLE -x
XTerm sudo apt install xterm xterm -T $TITLE -e

In Code::Blocks’ Environment settings window, on the left, click General settings. Most of the launch commands are pre-filled into the Terminal to launch console programs: drop-down box. Select the one you want, or paste yours into the box.

Set Up Todo List

The Todo List plugin displays a clickable list of all the //TODO, //NOTE, and //FIXME comments in the open files. In the Environment settings window, on the left, scroll down to Todo list.

Make sure Auto-refresh is UNCHECKED, and the Include the Todo list in the messages pane is CHECKED.

Important

At this point, make sure you click OK, save the workspace, and restart Code::Blocks.

Configuring Default Compiler Settings

While CMake handles our actual compiler flags, we need to change the default compiler settings in Code::Blocks a little to offer the C++14 standard. Most compiler settings should actually go either on Project ‣ Build Options... or in the CMake configuration files, but this one change should be global.

Go to Settings ‣ Compiler.... Make sure you’re in Global compiler settings ‣ Compiler settings ‣ Compiler Flags. Look for the option Have g++ follow the C++14 ISO.... If it is already in your list, then right-click on it, click ‘Modify flag’ and verify that the information matches the information in this list.

If the C++14 ISO standard is not in your list, look for the option Have g++ follow the C++14 ISO..., which should be under General. If you upgraded from an earlier version of Code::Blocks, it may be under Warnings. Right-click that option, and click New Flag....

Fill out (or verify) the options as follows:

  • Name: Have g++ follow the C++14 ISO C++ Language standard
  • Compiler flags: -std=c++14
  • Category: General
  • Supersedes: -std=c++98 -std=c++0x =std=c++11
  • Exclusive: False

Then, click OK. Make sure you check this option, to ensure the compiler always uses C++14. (Some of our code won’t work unless you’re on that standard!)

Configuring Source Formatter

It can be hard to be 100% adherent to standardized coding style. We make regular use of the AStyle plugin on Code::Blocks to make sure everything is formatted correctly before uploading. However, in order to use this plugin, it must be configured.

To get to these settings, go to Settings ‣ Editor... and, on the left, scroll down to Source formatter. Let’s walk through the settings, tab by tab, setting by setting.

Style

  • Bracket style: Allman (ANSI)

Brackets

  • Attach classes: no
  • Attach “extern c”: no
  • Attach namespaces: no
  • Attach inlines: no

Indentation

  • Indentation size (in space): 4
  • Use TABs instead of spaces: no
  • Force using TABs: no
  • Indent case: statement switches: YES
  • Indent classes: YES
  • Indent labels: YES
  • Indent modifiers: no
  • Indent namespaces: YES
  • Indent switches: no
  • Indent preprocessor blocks at bracket level zero: no
  • Indent multi-line preprocessor definitions ending with a backslash: no
  • Indent preprocessor conditionals: YES
  • Indent C++ comments beginning in column one: no
  • Minimal indent added...: 2
  • Maximum of # spaces to indent a continuation line...: 40

Formatting

  • Break closing headers...: YES
  • Break ‘else if()’ header combinations...: no
  • Add brackets to unbracketed one line conditional statements: YES
  • Add one line brackets to unbracketed one line conditional statements: no
  • Remove brackets from conditional statements: no
  • Don’t break one-line blocks: YES
  • Don’t break complex statements and multiple statements residing...: no
  • Convert TABs to spaces: YES
  • Closes whitespace in the angle brackets of template definitions: YES
  • Remove the preceding ‘*’ in multi-line comment...: no
  • Enable line breaking: YES
  • Break lines after amount of chars...: 80

Padding

  • Pad empty lines around header blocks: no
  • Insert space padding around operators: YES
  • Insert space padding around parenthesis on the outside: no
  • Insert space padding around parenthesis on the inside: no
  • Insert space padding between a header and the following paren: YES
  • Remove extra space padding around parenthesis: no
  • Delete empty lines within a function or method: no
  • Fill empty lines with the whitespace of their previous lines: no
  • Pointer alignment: Type
  • Reference alignment: Type

Changing Your Theme

Yes, there are multiple themes available for Code::Blocks! I’m glad of it, too, because I rely heavily on dark themes to be able to work for long periods of time.

You might have those themes already present. Go to Settings ‣ Editor..., and click Syntax highlighting on the left. Then, check the Colour theme: drop down box. If you see lots of options, pick the one you want.

Once you have a theme picked out, you can further fine-tune it to your liking by using the other controls on that panel. All the themes are fully customizable!

Installing Themes

If you don’t see any themes (besides default), you’ll need to set them up. First, close out of Code::Blocks. Download and save color_themes.conf to your computer.

In your terminal, run the following to backup your existing themes file and start the config editor.

$ cp ~/.config/codeblocks/default.conf ~/.config/codeblocks/backup.conf
$ cb_share_config

On the window that pops up, click the three dots under Source configuration file..., and browse to the color_themes.conf file you just saved. Then, click the three dots under Destination configuration file... and select default.conf, which should be sitting right in front of you on the browse window by default.

Next, check all the boxes on the left side. [Sorry, there’s no fast way to do that!] Click Transfer >>, confirm Yes, and then click Save and confirm Yes.

Finally, click Close.

Once you’ve done all that, start Code::Blocks, go to Settings ‣ Editor... ‣ Syntax highlighting. You can now browse the imported themes. Use the rest of the controls on that panel to customize any of them to your liking.

Further Configuring Environment Colors

Unfortunately, the color themes only affect code files themselves. It is possible to further customize some of the other environment colors to match.

To do this, you’ll first want to open a code file, so you can more easily sample the background color. Then, go to Settings ‣ Environment... ‣ Colours. Most of these colors can stay as-is, but there are a few I recommend changing to match your theme.

You can change any color by clicking its name, and then the color box at the right side of the panel. Then, tap the eyedropper towards lower-left, and click the color anywhere on your computer screen (even outside of Code::Blocks!) to sample it.

You will be using the background color (“Background”) and typical text color (“Text”) from your selected color scheme.

Change the following colors:

Color Change to...
Code completion: Documentation popup background Background
Code completion: Documentation popup text Text
Editor: Caret White for dark themes, black for light themes.
Code completion: Documentation popup link Similar to Text
Editor: Right margin I recommend a bright color that contrasts with the background.
Editor: Line numbers background colour Background
Editor: Line numbers foreground colour Text
Editor: Margin chrome colour Background
Editor: Margin chrome highlight colour Background
Start here page: Background colour Background
Start here page: Link colour Similar to Text
Start here page: Text colour Text

Once you’ve made your changes, click OK, and then save your workspace via File ‣ Save workspace.

That’s it! The essential setup is finished for Code::Blocks. I recommend you go back and browse through the other settings, and get familiar with the coding environment.