Compiling Stockfish on Windows

So you want to compile Stockfish on Windows! This guide shows you how.

System requirements: Any recent version of Windows. To compile a 64-bit version, you must be using a 64-bit version of Windows and have a 64-bit processor. To compile a SSE4.2/Popcount version, you must have a processor that supports such instructions (i.e. Core i3, i5, i7, etc.).

First, install MinGW (32-bit). Make sure to check the box to install MSYS.

Next, if you have a 64-bit machine and want to build 64-bit versions, download MinGW (64-bit), GCC 4.9.2.

After that finishes downloading, extract it and move the resulting mingw64 folder to C:\MinGW. So the directory C:\MinGW\mingw64 should exist.

Now you will need to set your PATH variable. Open Control Panel > System > Advanced System Settings > Environment Variables. That gives a dialog box with two sections, top and bottom. You need to enter a new variable into the top (users) partition. Click the "New" button. For variable name, type PATH. For variable value, type:

C:\MinGW\bin;C:\MinGW\msys\1.0\bin for 32-bit machines C:\MinGW\mingw64\bin;C:\MinGW\msys\1.0\bin for 64-bit machines

If you already have a PATH variable in the users list, you should append instead of replacing it, but that is not usually the case with user variables. There are likely conflicts in the system variables section (bottom) which seem better to avoid.

Use Windows Explorer to create a new Stockfish folder somewhere, for example at C:\Users\{username}\Stockfish

Prepare (or get) the source code you want to use. It should all be contained in a folder named src. For example the latest Stockfish source is available as a zipped file at https://github.com/official-stockfish/Stockfish/ (click the download button near lower right). Unzip then copy the src folder under your Stockfish folder, so it will appear like C:\Users\{username}\Stockfish\src

Now, using Command Prompt, navigate to the src folder with the cd (change directory) command. For example type: cd C:\Users\{username}\Stockfish\src

Then use one of the following commands depending on your processor architecture:

make profile-build ARCH=x86-32 COMP=mingw
make profile-build ARCH=x86-64 COMP=mingw
make profile-build ARCH=x86-64-modern COMP=mingw

After a bit, you should have a stockfish.exe file in the src folder. Type: strip stockfish.exe which will reduce it in size. Use Windows Explorer to rename it, for example stockfish 151417.exe (this is important, otherwise it will be deleted by the next operation). Type make clean to remove temporary files. Finally, close the Command Prompt window. You're all finished!

For a quick test of proper functionality, run/open the Stockfish.exe file directly, and enter uci. Then try bench.