-
Notifications
You must be signed in to change notification settings - Fork 26
MinGW Build Tutorial
NOTICE: This tutorial is still under construction, and may be incomplete!
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\
).
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.
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:
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.
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:
g++ --version
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
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
This will take a long time, as you're compiling all of boost. 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:
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.
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-master 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:
...