Skip to content

MinGW Build Tutorial

Nicholas "LB" Braden edited this page Oct 4, 2015 · 31 revisions

This tutorial is outdated (for now) - good luck.

This tutorial is for Windows users.

This tutorial teaches you how to:

  • Download and install MinGW
  • Download and install CMake
  • Download and build Boost (unless you have a 64-bit computer)
  • Download, build, and install SFML
  • Build and Run ChessPlusPlus

Note: if at any time you encounter an error about missing a libiconv-2.dll file, you can download my copy here until the bug is fixed. Place it in your MinGW bin folder (usually C:\MinGW\bin\).

Installing MinGW for 32-bit Computers

MinGW, short for "Minimalist GCC for Windows", is a compiler for Windows based on the GCC compiler. If you have a 64-bit computer, skip this step and go to the step for 64-bit computers instead.

To start, download the MinGW installer from here:

http://sourceforge.net/projects/mingw/files/ "mingw-get-setup.exe"

Install the manager, and when the window opens, make sure you install at least these components:

Then, from the menu, choose "Installation" -> "Apply Changes", then click "Apply". Then, you just have to wait for everything to be downloaded and installed for you. While you wait, you can also read through later steps so you know what you're in for.

Once everything is installed, you can close the manager window. Next, we need to add MinGW to your system PATH variable. This is an advanced step and can be dangerous if you mess up, so be careful!

Open your start menu and right click on "Computer" and choose "Properties". On the left hand side of the window that opens, choose "Advanced System Settings". In the new window that opens, click the "Environment Variables..." button. Scroll down in the lower list to find the PATH variable:

Double-click it or click the "Edit..." button, then carefully, at the very beginning of the text, add a semi-colon, and then before the semi-colon, add the text "C:\MinGW\bin" without quotes. It will look similar to the screenshot above.

After this, click OK out of all the windows, and press WinKey+R - a "Run" dialog appears, type "cmd" without quotes and hit enter. A console window should appear - in this, type the following command and verify that you've done all the steps correctly up to now:

g++ --version

If your output is similar to the above, you've done everything correctly and can move on to the next step.

Installing MinGW for 64-bit Computers

This is significantly easier, since there is a distribution known as "nuwen MinGW" which has boost already included, among other things.

To download and install, simply download nuwen MinGW from here:

http://nuwen.net/mingw.html

After installation, you need to navigate to C:/MinGW/bin/ and find the file make.exe - copy and paste this, and rename the copy to mingw32-make.exe. This will allow CMake to recognize that you have MinGW installed. You should also still have the original make.exe - don't delete it, you will want both.

Next, we need to add MinGW to your system PATH variable. This is an advanced step and can be dangerous if you mess up, so be careful!

Open your start menu and right click on "Computer" and choose "Properties". On the left hand side of the window that opens, choose "Advanced System Settings". In the new window that opens, click the "Environment Variables..." button. Scroll down in the lower list to find the PATH variable:

Double-click it or click the "Edit..." button, then carefully, at the very beginning of the text, add a semi-colon, and then before the semi-colon, add the text "C:\MinGW\bin" without quotes. It will look similar to the screenshot above.

After this, press OK out of all the winds and press WinKey+R - a "Run" dialog appears, type "cmd" without quotes and hit enter. A console window should appear - in this, type the following command and verify that you've done all the steps correctly up to now:

g++ --version

Downloading & Installing CMake

CMake, short for "Cross-patform Make", is a tool that allows projects to easily be built with a multitude of compilers on a multitude of systems. You need CMake for both SFML and ChessPlusPlus.

Simply download and install the latest version of CMake:

http://www.cmake.org/cmake/resources/software.html (Look under "Binary Distributions" for Windows)

Make sure you choose to add CMake to the system PATH. If you are not given this option, you will have to do it yourself - just be careful!

After this, press WinKey+R - a "Run" dialog appears, type "cmd" without quotes and hit enter. A console window should appear - in this, type the following command and verify that you've done all the steps correctly up to now:

cmake --version

Downloading & Building Boost (32-bit only)

Note: skip this step entirely if you have a 64-bit computer.

Boost is a large library for doing everything you could ever want to do in C++ - it is the go-to library for just about everything. Boost is used in ChessPlusPlus, so to get started, download the latest version:

http://www.boost.org/users/download/

Once you've downloaded it, extract it to somewhere in a path with no spaces in any part of the path. For myself, I have extracted the archive to C:\Users\Nicholas\Code\, and in the Code folder there is now a folder called boost_1_54_0 (the version number may be higher for you).

Open the new folder and then press WinKey+R - a "Run" dialog appears, type "cmd" without quotes and hit enter. A console window should appear - in this, type "cd " without quotes, but with the space, and then copy and paste the path to the boost folder into the console window. You cannot paste into the console window with Ctrl+V - instead, right click anywhere on the console window and choose "Paste". Then, hit enter. Your screen should look something like this:

Next, paste in each of these commands and hit enter:

bootstrap.bat mingw

After this, paste and run:

b2 toolset=gcc variant=release link=static --with-system --with-filesystem

Check the console window periodically to see if it has finished. Once it has finished, you can close the console window and move on to the next step. When it has finished, it will look similar to this:

Downloading & Building SFML

SFML, an acronym for `Simple and Fast Multimedia Library", is a fast and simple library for multimedia, such as graphics, sounds, networking, and more. Like boost, it is written in C++ for C++.

The correct version of SFML to use is included in the ChessPlusPlus repository - navigate to the lib folder using the online interface:

https://github.com/cpluspluscom/ChessPlusPlus/tree/master/lib

Click on the commit hash next to SFML:

This will take you to the correct version of SFML to use. On the right-hand side of the screen, choose to download the repository:

Once you've downloaded it, extract the archive to a path with no spaces in any part of the path (as with boost). For myself, I have extracted the archive to C:\Users\Nicholas\Code\, and in the Code folder there is now a folder called SFML-* where * is the commit hash.

Open the new folder and then create a new folder within it called "build", and go into this folder. Now, press WinKey+R - a "Run" dialog appears, type "cmd" without quotes and hit enter. A console window should appear - in this, type "cd " without quotes, but with the space, and then copy and paste the path to the boost folder into the console window. You cannot paste into the console window with Ctrl+V - instead, right click anywhere on the console window and choose "Paste". Then, hit enter. Your screen should look something like this:

Next, paste in this command to have CMake generate makefiles for MinGW:

cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=0 ../

After this, paste this command to have MinGW build SFML and install it for you:

mingw32-make install

If you encounter an error with sfml-main, navigate to SFML-*\src\SFML\Main\ and open SFML_Main.cpp, the at the end of line 33 which reads #if defined(_WIN32), add && 0 to the end so it reads #if defined(_WIN32) && 0. This is a workaround for certain environments where _WIN32 is defined but __argc and __argv are not. Then, re-run mingw32-make install.

After it has successfully built SFML, it should copy files to your Program Files folder in an SFML subfolder. Keep track of whether this is Program Files or Program Files (x86) - you will use it in the next step. You can now close the console window and move on to the next step.

Building & Running ChessPlusPlus

ChessPlusPlus, like SFML, uses CMake to generate project files for your system.

First, you need to download the ChessPlusPlus project - you can do this either via the official repo, or via one of the forks if you want to test someone else's version (e.g. LB's version). Navigate to one using the web interface, and n the right-hand side of the screen, choose to download the repository:

Once you've downloaded it, extract the archive somehwre. For myself, I have extracted the archive to C:\Users\Nicholas\Code\, and in the Code folder there is now a folder called ChessPlusPlus-lb-refactor (or ChessPlusPlus-master if you used the official repo). Navigate into this folder, and within it create a folder called build, but don't enter it yet, as we're not done.

In the lib folder, notice that the SFML and json-parser folders are empty - we took care of SFML already, but we need to get JSON-parser. On the web interface for whichever repository you chose to download, go into the lib folder and click on the commit hash next to json-parser:

This will take you to the correct version of json-parser to use. On the right-hand side of the screen, choose to download the repository:

When the archive opens, don't extract it - instead, navigate inside the json-parser-<commit hash> folder and copy all the files into the /lib/json-parser/ folder. After this, go back out of the lib folder, and enter the build folder we made earlier.

Now, press WinKey+R - a "Run" dialog appears, type "cmd" without quotes and hit enter. A console window should appear - in this, type "cd " without quotes, but with the space, and then copy and paste the path to the boost folder into the console window. You cannot paste into the console window with Ctrl+V - instead, right click anywhere on the console window and choose "Paste". Then, hit enter. Your screen should look something like this:

Now, modify this command to fill in the blanks and paste it into the console:

cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=RELEASE  -DSTATIC_BUILD=1 -DSFML_ROOT="<SFML Installation>" -DBOOST_ROOT="<Boost Directory>" ../

If your SFML installed to "Program Files (x86)", then replace <SFML Installation> with C:/Program Files (x86)/SFML

If your SFML installed to "Program Files", then replace <SFML Installation> with C:/Program Files/SFML

If you have a 32-bit computer, replace <Boost Directory> with wherever you extracted boost - in my case this would be C:\Users\Nicholas\Code\boost_1_54_0.

If you have a 64-bit computer, replace <Boost Directory> with C:\MinGW.

As an example, here is the command line I use on my 32-bit system:

cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=RELEASE  -DSTATIC_BUILD=1 -DSFML_ROOT="C:/Program Files/SFML" -DBOOST_ROOT="C:\Users\Nicholas\Code\boost_1_54_0" ../

And this is the command line I use on my 64-bit system:

cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=RELEASE  -DSTATIC_BUILD=1 -DSFML_ROOT="C:/Program Files (x86)/SFML" -DBOOST_ROOT="C:\MinGW" ../

Note: it's OK to mix forward and reverse slashes on Windows, they are treated the same. On other operating systems, however, always use forward slashes.

After running the appropriate command, run this to actually compile and link ChessPlusPlus:

mingw32-make

After having successfully compiled and linked ChessPlusPlus, run cd ../ in the console window to go up one directory, then run this command to test out ChessPlusPlus for yourself:

"./build/chesspp.exe"

If it runs, try playing a game of chess against yourself or a friend. If it crashes, figure out the simplest way to reproduce it, then open an issue in the repository you tried out, including the content of debug_log.log, debug_err.log, and debug_out.log. Enjoy!