How to cake, make and compile C ++ 14 on Windows

I'm trying to compile a C ++ project in Windows 10 that uses C ++ 14 features like std::make_unique<> and the like.

I would like to easily compile on the command line using CMake and make, and then be able to run my program from any command line or simply by clicking on its executable.

Compiling using Cygwin, even if it really works (I used this tutorial ), is not an option, since the resulting executable file cannot be used outside of the Cygwin environment due to the lack of DLLs.

I read about MinGW-w64, but it looks like the latest version for Windows conforms to GCC 4.8.3 .

The same goes for the MinGW installer mingw-get-setup.exe here , which allows me to install 4.8. 1-4 versions.

So, I would like to have a procedure on how to compile a C ++ 14 project using CMake, and this will allow me to run the executable in Windows by default.

Thanks.

Update: Chris Drew commented that I can use the latest version of Visual Studio to create my project using the Visual C ++ compiler instead of GCC. I have described the workflow in detail in my answer, but I'm still looking for a way to use it with “GNU-style”.

"GNU-style": Use the link provided in the Tive commentary to install the GCC 5.1 working environment and use regular cmake . -G"Unix Makefiles" && make cmake . -G"Unix Makefiles" && make .

See more about both solutions.


+4
source share
1 answer

Using the Visual Studio Compiler

Following Chris Drew's comment , here's what I did to compile using CMake to create a Visual Studio 2015 solution and compile this solution on the command line.

Note that this does not use the GNU toolchain, as we will not use gcc / make, but the Visual C ++ compiler.

Create and move to the assembly subdirectory (recommended, since it will generate many files, not just the standard Makefile):

 mkdir build && cd build 

Creating a Visual Studio 2015 solution:

 cmake . -G"Visual Studio 14 2015" 

This will create several project files, including YourProjectName.sln , which we will use to create the project using the following command:

 msbuild YourProjectName.sln 

Note that msbuild not in my PATH, so I had to provide the full path to the executable, which was in my case C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe .


Using the Updated MinGW Installer

Tive provided a link in the installer kit that will automatically install GCC 5.1 on your system, so you can use the usual GNU toolchain by creating a Unix Makefile and using the make .

Please note that you will need to edit your PATH manually, as the installer does not do this for you.

+2
source

All Articles