I need to use C::B with a recent version of MS VC++ compiler like the ones in VS2015 or VS2017, and eventually future ones, but C::B does not offer such option. The most recent VC++ version that C::B allows the user to choose from its list, in the Settings, is VC++2010 (MSVC++10.0) wich is quite old. After some search I didn't find an explanation to overcome the problem. Not even C::B site offers a solution. How can I do that?
After some attempts I made with C::B settings and VC++ compilers, I found a solution that is not complicate at all. In this post I will show how to use the latest versions of VC++ compiler (MSVC++ 14.0 or higher) with CodeBlocks - with no need to install Visual Studio. The solution would be identical if you prefer to use Visual Studio instead.
I will answer the question for 32 and 64 bits projects. By default it will support std C++14.
Content:
A) Install the latest version and compile for x86 projects;
B) Change to C::B 64bits projects.
A) Install and use for 32bits projects
Install the latest version of VC++ compiler.
The VC++ Toolset can be obtained through NuGet.
To get NuGet look here: NuGet.
Run the following command from the command line. The command installs the latest version is (according MSDN):c:\\> nuget install VisualCppTools.Community.Daily.VS2017Layout -Version 14.14.26423-Pre -Source https://visualcpp.myget.org/F/dailymsvc/api/v3/index.json
Install Microsoft Build Tools 2015 (or higher). Here I will stick with 2015, but you can go for 2017.
For 2015 the installer is here BuildTools2015. Run it to install the tools.
Open C::B and configure it. C::B last version for Microsoft Visual C++ is 2010. We can use it, but seting a more recent compiler.
3.1 Go to Settings>>Compiler
3.2 In "Selected Compiler" select MS visual C++ 2010. This is the higher version available in C::B.
3.3 Select the Tab "Toolchain executables" and set the Compiler's directory with the directory with the VC++ Toolset. In my case:D:\VisualCppTools.14.0.25114-Pre\lib\native
Confirm if the "Program Files" boxes of the tab are filled.
3.3 Select "Search directories" tab.
3.3.1 In "Compiler" tab add the include directory path.
In my case is:D:\VisualCppTools.14.0.25114-Pre\lib\native\include
Possibly the following will also be needed (from Build Tools).C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
Also if not already there and if needed (in my case)C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um
3.3.2 In "Linker" tab enter the paths for the libs. In my case.D:\VisualCppTools.14.0.25114-Pre\lib\native\lib
Possibly, also,C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x86
And if your project complains about uuid.lib, then insert also (in my case),C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86
3.3.3 "Resource compiler" tab. This is optional. In my case,D:\VisualCppTools.14.0.25114-Pre\lib\native\include
And that's it! But if we prefer, C::B allow us to change the compiler name.
B) Change the C::B project settings for x64 projects
Point linker libraries' paths to their x64 counterparts. In the Settings menu choose "Search Directories">>"Linker".
1.1 For the compiler library, add "amd64". In my case:D:\VisualCppTools.14.0.25114-Pre\lib\native\lib\amd64
1.2 For "ucrt" and "um" add "\x64" to the paths. Example for my case:C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64
For the compiler select the Tab "Toolchain executables" and insert the prefix "amd64\" for C++ compiler and Make program, as: amd64\cl.exe, amd64\nmake.exe
Again, that's it!
Good work!
Below are compiler options entries for MSVC 2015 installation on Windows 7 when compiling a "plain" C++ console application (no CLI) for a x86 target machine:
INCLUDE=
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
C:\Program Files (x86)\Windows Kits\8.1\Include\um
C:\Program Files (x86)\Windows Kits\8.1\Include\shared
C:\Program Files (x86)\Windows Kits\8.1\Include\winrt
LIB [x86]=
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\lib
C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x86
C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x86
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\Lib\um\x86
LIBPATH=
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\lib
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib
I added INCLUDE
and LIB
to search directories for compiler and linker, respectively, and everything worked in C::B for a x86 console application.
I didn't experiment with x64 architecture...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With