For this course, we will be using the Code::Blocks IDE along with the GCC 4.8.1 (or more recent) compiler.
Code::Blocks and the GCC 4.8.1 compiler is known to work well on Windows 7, Windows 9, and Windows 10. Specific notes on installing Code::Blocks on Windows appear below.
Most Linux distributions have a Code::Blocks package. You should use your package manager to install it. However, be aware of the following minimum distribution requirements:
After installing, jump to After installing.
There is a version of Code::Blocks for MacOS, but it is claimed to be buggy. In addition, I don't know if it supports C++11 (the version of C++ used in this course). You might be better off with Eclipse CDT or Xcode, but I don't know what is involved in making either C++11 compliant.
Download codeblocks-13.12mingw-setup-TDM-GCC-481.exe
from the Code::Blocks Download binary page.
Be sure you download codeblocks-13.12mingw-setup-TDM-GCC-481.exe
. Do not download codeblocks-13.12-setup.exe
or codeblocks-13.12mingw-setup.exe
.
The download links are on the right. The last time I tried, the BerliOS link wasn't working, but the Sourceforge.net link worked fine.
After downloading, double click the installer to start the installer. Accept all the defaults and install Code::Blocks.
In the unlikely event that you have a previous Code::Blocks installation (or you have installed the MinGW compiler for other purposes), you will have to completely uninstall the previous Code::Blocks version, delete C:\Program Files\MinGW
, and remove C:\MinGW\bin
and C:\MinGW\MSYS\1.0\bin
from your PATH
before installation.
You may have more than one compiler installed on your computer. To keep you from having to manually set the proper compiler each time you start a new project, verify that the desired compiler is set as the default by doing the following:
C:\Program Files\CodeBlocks\MinGW
or C:\Program Files (x86)\CodeBlocks\MinGW
. On Linux, this field will probably be set to /usr
, meaning that it will use the system-provided GNU GCC tools.Do not skip this step! If you do, you will encounter various hard-to-diagnose problems later in the course.
There are several official (as well as unofficial) versions of C++ in common use. We will be learning C++11, which is a relatively new standard. Code::Blocks needs to be told that you want to use this version of C++ rather than an older one.
To do this:
-std=c++11
to the text area and click “OK”.
The project you just created should open. You can see the source code for the project if you expand {name-of-the-project} and “Sources”. (Make sure the “Projects” tab is selected in the left panel.) Double click on main.cpp
to open it in the editor.
You should see some information about the building process in the lower panel, and after a short time you should see a terminal window that says “Hello world!” on the first line and “Press any key to continue” on the last line. Pressing any key will close this window.