Enabling C++14 features in code::blocks will also enable the C++11 features.In this post we will see how to enable C++14 features in code::blocks.
First of all I believe you have Code::blocks installed in your computer.If you have not installed it go to the link here Code::blocks and download the latest version(In the time of writing this post the latest version is 16.01).If you have lower version we can still enable C++14 features but it is better that you have the latest version(but if you have the lower version and do not want any extra work go directly to the next section).There will be two links for the download:
i)One is without MinGw Compiler.The file name looks like this “codeblocks-16.01-setup.exe“.
ii)The other is with MinGW compiler.The file name looks like this “codeblocks-16.01mingw-setup.exe“.
You can download any of the files and install it.
Downloading higher version of MinGW
The lower version of MinGW does not support C++14 features.So we will use a higher version of MinGW.You can download the higher version here https://nuwen.net/mingw.html.In my time of writing this post the latest MinGW version available is 6.1.0.This version support all the C++14 features.Install this latest version in the directory “c:/” by running the .exe file.
After installing the MinGW get the directory of the binary files,which is the directory “C:\MinGW\bin” and add it in the environment variables.Read the next section on how to add the directory in the “environment variables”.
Adding the directory “C:\MinGW\bin” in the environment variables
Go to “This PC” or “My Computer” ,right click and click on the “properties” ,you will see a new window.The screen shot is provided below.
And click on the “Advanced System Setting” .This will take you to new Window screen which is shown below.
In this Window click on the “environment Variables” button.This will take you to new Window,the screen shot is provided below.
Double click on the “Path” under the ‘System Variable‘ section.Double clicking on the ‘Path‘ will open a new window.In this new window click on the ‘New‘ button and add the directory “C:\MinGW\bin“.The screen shot is provided below.
After adding the directory click ‘Ok‘ and restart your computer.After restarting your computer go to next section.
Stop wasting time,earn money($$$) from your website-Join Now!
Integrating the higher MinGW version with code::blocks
Open your code::blocks click on “settings” and click on “Compiler..” a new window will pop up.In this new window go to “toolChain executables“.The screen shot is provided below.
In this window we will change some settings.Under the “Compiler’s installation directory” select the “..” button and select the directory “C:/MinGW“.After this,
i)Go down below under ‘Program files‘ and for ‘C compiler‘ click the button ‘..‘ and go to the directory “C:/MinGW/bin” and select “gcc.exe” .
ii)Go down again and for “C++ compiler” click the button ‘..‘ and go to the directory “C:/MinGW/bin” and select “g++.exe“.
iii)Go down again and for ‘Linker for dynamics libs‘ click the button ‘..‘ and go to the directory “C:/MinGW/bin” and select “g++.exe“.
iv)Go down again and for ‘debugger’ you need not do anything so skip this line.
v)Go down again and for ‘Resource compiler‘ click the button ‘..‘ and go to the directory “C:/MinGW/bin” and select “windres.exe“.
vi)Go down again and for ‘Make program‘ click the button ‘..‘ and go to the directory “C:/MinGW/bin” and select “mingw32-make.exe“.
After this click ‘Ok‘.The screen shot below might help you.
After clicking ‘Ok‘ go again to the “Settings” and click on “compiler..” under ‘Compiler flags‘ check the box which states “Have g++ follow the C++14 ISO C++ language standard [-std=C++14]“.If you do not find this box don’t do anything,the C++14 is already enabled.
Now to enable the Debugger go again to ‘settings‘ select ‘Debugger..‘ and select the “Default” in the left column and change the ‘executable path‘ to ‘C:\MinGW\bin\gdb.exe ‘ and click ‘Ok‘.C++14 is now enable.
To verify that C++14 features is enable.Create a project.Copy the code below and paste it in your main.cpp.
constexpr int func()
cout<< func( ) ;
If everything goes well you get output as
This also means C++14 is enabled.