How to enable C++14 in Code::Blocks?

To compile your source code using the C++14 flag in Code::Blocks, you first of all need to download and install a compiler that supports C++14 features.

Here’s how you can do it on Windows:

1. Download MinGW fromĀ here (particular build) or from official site
2. Extract it to for example: C:\ (result will be C:\MinGW)
3. Open Code::Blocks
4. Go to Settings => Compiler.

CB_1

5. Go to “Toolchain Executables”.
6. In the top field “Compiler’s installation directory”, change the directory to the one where you extracted the compiler. E.g C:\MinGW.
7. Change all the necessary files under “Program Files” to match the files under C:\MinGW\bin:

CB_2

8. Before you hit “OK”, go to the leftmost tab “Compiler settings”.
9. Select “Compiler Flags”.
10. Right click in the list somewhere and select “New Flag”:

CB_3

11. Type in the following:

CB_4

12. Click “OK” and tick the box you just created:
CB_5

13. Specify the debugger path. Go to “Settings” => “Debugger”, click “Defualt” on left hand side and enter the new full path of the executable:

CB_6

And finally, create a new C++ project and test if it’s working:

#include <iostream>
#include <string>
using namespace std;

auto main() -> int
{
    auto add_two([](auto x, auto y){ return x + y; });

    cout << add_two("I"s, "t"s) << " works!" << endl;
}
How to enable C++14 in Code::Blocks?

Leave a comment