Compiling BerryBots on Windows with MinGW

From BerryBots Wiki
Jump to: navigation, search


The BerryBots source code is available at the GitHub repo or on the Downloads page.

Install MinGW

Before you can compile anything, you need a C++ compiler. MinGW is used to build the official BerryBots binaries for Windows.

Download and install MinGW and add MinGW\bin to your PATH. Depending on your version of Windows, this is somewhere like My Computer > System Properties > Advanced > Environment Variables. If you can't find it, a quick Google search should help. You may also need to grab 7-zip or similar for extracting some of the source code downloads.

If you're more comfortable with another compiler, it should work fine, but some of these instructions may be slightly off. (Please feel free to contribute build instructions for other Windows C++ compilers to the wiki.)

Compile dependencies

To compile BerryBots, we need to link against four external libraries: SFML 2.x, wxWidgets 2.9.x, libarchive, and zlib. The first three are compiled from source for the BerryBots binary releases. Those instructions are included below. The zlib folks recommend just taking their pre-built zlib1.dll instead of building it yourself, so that's what we do.


BerryBots uses SFML 2.0 for the main game graphics. Note that SFML has their own instructions for building SFML 2.0 with CMake, which may be helpful.

First, download and install CMake from and add it to your path. Then grab the source from the SFML downloads page or the GitHub repo. Note: SFML 2.1 has a Windows bug that affects BerryBots [1]. Use 2.0 or the latest code from GitHub for now.

Launch a command prompt and change into the SFML source directory. Use CMake to generate the build files that are used for actual compilation with MinGW, then use mingw32-make to compile SFML.

C:\> cd C:\SFML-master
C:\SFML-master> md build
C:\SFML-master> cd build
C:\SFML-master\build> cmake .. -G "MinGW Makefiles"
C:\SFML-master\build> mingw32-make

When it completes, you should have a lib subdirectory with the SFML library files (*.a and *.dll).


We use wxWidgets 2.9.x for everything besides the main game window - all the dialogs and menus for configuring battles, packaging ships and stages, and viewing ship/stage output consoles. wxWidgets has their own instructions for compiling wxWidgets with MinGW, which may be helpful.

Download wxWidgets 2.9.x source code (with DOS line endings) from the wxWidgets downloads page. Extract it somewhere, launch a command prompt, and navigate to the wxWidgets\build\msw directory. Then compile wxWidgets with mingw32-make.

C:\> cd C:\wxWidgets-2.9.5\build\msw
C:\wxWidgets-2.9.5\build\msw> mingw32-make SHELL=CMD.exe -f makefile.gcc ^

This will take a few minutes to compile. Note the SHARED=0 parameter - this builds wxWidgets for static linking. This means that when you run BerryBots, you won't need to keep the wxWidgets libraries around, as the required code is compiled directly into BerryBots.exe. BerryBots works fine with shared libraries, too, but it means you have to lug around 60 megs of wxWidgets .dll's instead of just having an extra ~8 megs in your executable file.

When it completes, you should have a lib subdirectory with the wxWidgets library files.

libarchive with zlib

We use libarchive with zlib for packaging ships and stages as tarred / gzipped (.tar.gz) files. The gzip compression itself is handled by zlib, which libarchive depends on, so you need to grab that first: look for zlib compiled DLL at Download and extract it.

Next, download libarchive from - v3.1.x is used for the official BerryBots binary releases. Extract that somewhere, launch a command prompt, and change into the libarchive\build directory. Then run CMake, pointing at the zlib files, and mingw32-make.

C:\> cd C:\libarchive-3.1.2\build
C:\libarchive-3.1.2\build> cmake ^
-DZLIB_LIBRARY:FILEPATH="C:\zlib127-dll\lib\zdll.lib" ^
-DZLIB_INCLUDE_DIR:PATH="C:\zlib127-dll\include" .. -G "MinGW Makefiles"
C:\libarchive-3.1.2\build> mingw32-make

When it completes, you should have libarchive\libarchive_static.a under the build directory.

Compile BerryBots

Once we've compiled the dependencies, we can build BerryBots itself.

Download the source from the downloads page or the GitHub repo. Extract it where ever you like and update the Makefile with the paths where you built SFML, wxWidgets, libarchive, and extracted zlib. You might have something like:

SFML_PATH = C:\SFML-master
WXWIDGETS_PATH = C:\wxWidgets-2.9.5
LIBARCHIVE_PATH = C:\libarchive-3.1.2
WIN_ZLIB_PATH = C:\zlib127-dll

Now you just need to run mingw32-make windows from a command prompt in the BerryBots source directory. When it completes, you should have BerryBots.exe and you're good to go!

Note about MinGW DLLs

If you don't want to have MinGW on your path, or you want to copy BerryBots to other computers that don't, you need to copy some DLLs over from the MinGW directory: copy libgcc_s_dw2-1.dll, libstdc++-6.dll, and pthreadGC2.dll into the directory where you have BerryBots.exe.

CLI version

The BerryBots source package also contains a version of BerryBots that launches individual matches from the command line. This is how things worked on Mac and Linux in v1.0.x, and how things still work on the Raspberry Pi.

You may find this useful, such as for running matches from other programs or running BerryBots from the command line on a remote system - you could use -nodisplay -savereplay and then view the replay in a browser. The code for this is in bbsfmlmain.cpp.

To compile this version of BerryBots on Windows, run mingw32-make wincli. Then run matches or package ships or stages with berrybots.exe (not

  berrybots [-nodisplay] [-savereplay] <stage.lua> <bot1.lua> [<bot2.lua> ...]
  berrybots -packstage <stage.lua> <version>
  berrybots -packbot <bot.lua> <version>
Personal tools