Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to compile, on Windows 10, a C++ project that is using C++14 features such as std::make_unique<> and things like that.

I'd like to be able to compile easily in command line, using CMake and make and then be able to run my program from any command line or just by clicking it's executable.

Compiling using Cygwin, even if it's indeed working (I used this tutorial), is not an option since the resulting executable won't be usable outside of the Cygwin environment due to missing DLLs.

I've read about MinGW-w64, but it seems like the latest available version for Windows corresponds to GCC 4.8.3.

Same goes for the MinGW installer mingw-get-setup.exe available here, wich only allows me to install the 4.8.1-4 version.

So I'd like to have a procedure on how to compile a C++14 project using CMake, and that will allow me to launch the executable in the default Windows environment.

Thanks.

Update : Chris Drew commented that I could use the latest Visual Studio version to build my project using the Visual C++ compiler instead of GCC. I detailed the workflow in my answer, but I'm still looking for a "GNU-style" way to compile it.

"GNU-style" : Use the link provided in Tive's comment to install a working GCC 5.1 environment and use the normal cmake . -G"Unix Makefiles" && make commands.

See this answer for more details on both solutions.


like image 887
AntoineB Avatar asked Oct 30 '22 21:10

AntoineB


1 Answers

Using Visual Studio compiler

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

Note that this is not using the GNU toolchain as we won't be using gcc / make but the Visual C++ Compiler.

Creating and moving to a build subdirectory (it's recommended since it will generate a lot of files, instead of just a standard Makefile) :

mkdir build && cd build

Generating the Visual Studio 2015 solution :

cmake . -G"Visual Studio 14 2015"

This will generate several project files including YourProjectName.sln that we will use to build the project using the following command :

msbuild YourProjectName.sln

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


Using an updated MinGW installer

Tive provided a link to a bundled installer that will automatically install GCC 5.1 on your system, this way you can use the normal GNU toolchain by generating an Unix Makefile, and using the make command.

Note that you will need to edit your PATH manually as the installer is not doing it for you.

like image 57
AntoineB Avatar answered Nov 15 '22 04:11

AntoineB