Building Spring on Windows: Difference between revisions

From Spring
Jump to navigationJump to search
Flozi (talk | contribs)
Reword & correct grammar
Flozi (talk | contribs)
→Compiling with MinGW: update to currently working instructions
Line 19: Line 19:
=Compiling with MinGW=
=Compiling with MinGW=


== requirements ==
== Requirements ==
install [http://www.cmake.org/ cmake] and [http://www.7-zip.org 7-zip] and [http://msysgit.github.io/ msysgit].
install [http://www.cmake.org/ cmake] and [http://www.7-zip.org 7-zip] and [http://msysgit.github.io/ msysgit].


== installing mingw ==
== Installing MinGW ==
Compiling Spring in MinGW requires >=GCC 4.x.
Compiling Spring in MinGW requires MinGW-W64


Because the official MinGW installer and packages are outdated, we recommend to use the TDM web-installer instead, to install the official <code>MinGW Stable</code> (not <s><code>TDM-GCC</code></s>) package:
Download and run the "Mingw-builds project - native toolchains using trunk" installer from [http://mingw-w64.sourceforge.net/download.php MinGW-w64].


==TDM webinstaller==
Download and run the [http://tdm-gcc.tdragon.net/download On-Demand Installer] (tdm-gcc-webdl).


Select at least the following components:
Select the following options:


[[File:400px-Mingwscreenshot.jpg|right|400px]]
[[File:InstallingMinGW-w64.png|right|400px]]


* gcc (version: <u><code>MinGW Stable</code></u>!)
* '''Version:''' Any version above 4.8.x should work, 4.9.x+ may not have been tested as thoroughly.
** core
* '''Architecture:''' i686
** g++
* '''Threads:''' posix
** openmp (not needed anymore, but nice to have)
* '''Exception:''' sjlj <span class="note">This is the only setting which needs to be changed from the default</span>
* binutils
* '''Build Revision:''' The latest one
* mingw-runtime
* w32api
* mingw32-make (if you have no Make installed yet)
* gdb (recommended for debugging)
 
<div style="clear:both;"></div>


===Possible Problems===
===Possible Problems===
* If you get <span class=warning>undefined reference to `_Unwind_Resume'</span> linking errors, deinstall ''whole'' TDM/MinGW and reinstall it with ''dwarf2'' (<code>MinGW Stable</code> should have it enabled). If you are sure you have the dw2 version, and linking still fails, you should try reverting your mingwlibs to an older state (this applies to engine version 96.0 MASTER) by changing directory to /mingwlibs and issuing a  '''git checkout 11ddb74db6b86945e6485c8f76c3fdf063a28b2d''' command.
* If you get <span class=warning>undefined reference to `_Unwind_Resume'</span> linking errors, deinstall ''whole'' MinGW and reinstall it with ''sjlj''.


* When you installed an old version of MinGW/TDM and forgot to deinstall it correctly, <code>gcc.exe</code> & <code>g++.exe</code> will be named <code>gcc-dw2.exe</code>/<code>g++-dw2.exe</code>. CMake will then fail to find the correct one, first try to deinstall anything mingw related and reinstall everything. If that didn't helped just rename the files. If even that doesn't help open cmake-gui and click the advanced button and set the paths to the correct files yourself (<code>CMAKE_C_COMPILER</code> & <code>CMAKE_CXX_COMPILER</code>).
* When you installed an old version of MinGW/TDM and forgot to deinstall it correctly, <code>gcc.exe</code> & <code>g++.exe</code> will be named <code>gcc-dw2.exe</code>/<code>g++-dw2.exe</code>. CMake will then fail to find the correct one, first try to deinstall anything mingw related and reinstall everything. If that didn't helped just rename the files. If even that doesn't help open cmake-gui and click the advanced button and set the paths to the correct files yourself (<code>CMAKE_C_COMPILER</code> & <code>CMAKE_CXX_COMPILER</code>).
Line 76: Line 68:
* ''optional:'' for multi-threaded compilation, the ''mingw32-make'' part may differ on your system: <code>''<pre>set MAKE_COMMAND=mingw32-make -j2</pre>''</code> (use -j4 for 4 threads)
* ''optional:'' for multi-threaded compilation, the ''mingw32-make'' part may differ on your system: <code>''<pre>set MAKE_COMMAND=mingw32-make -j2</pre>''</code> (use -j4 for 4 threads)
* compile with: <code>''<pre>mingw32-make install-spring</pre>''</code>
* compile with: <code>''<pre>mingw32-make install-spring</pre>''</code>
* compile just the engine (spring.exe) with: <code>''<pre>mingw32-make engine-default</pre>''</code>
* compile just the engine (spring.exe) with: <code>''<pre>mingw32-make engine-legacy</pre>''</code>


===Generating the AI Sources/Wrappers===
===Generating the AI Sources/Wrappers===

Revision as of 18:21, 23 July 2014

Development < Building Spring < Building Spring on Windows


If you only want to produce your own Spring game and not contribute to the core engine, compilation is not necessary. Check out Gamedev:Main.

Warning: Compiling Spring on Windows often causes problems, it is heavily recommended to use Linux for developing the Spring RTS Engine if possible.

Some reasons for this:

  • Of the active developers nobody uses windows for developing. So they might not be able to help as effectively as on Linux.
  • Setting up a build environment takes a lot more time on windows
  • Compiling is often slower on windows
  • Compiling on windows is poorly tested (which possibly leads to some random / unknown / weird errors)

Get the Source Code

Tarballs

(For playing online official games on lobby.springrts.com - the spring lobby server)

Using Git is the recommended way to get the sources of the engine. In spite of, you can use the official tarballs to compile Spring without git.

Note: Do NOT use the zip-files from github, they are missing important data to compile Spring.

See Building spring for build instructions.

Git

Spring project page at github

Master repo URI: git://github.com/spring/spring.git
Backup repo: git://git.code.sf.net/p/springrts/code

Branches of interest:

  • master - latest stable, enforced for official games on lobby.springrts.com
  • maintenance - fixes for the latest stable
  • develop - major developments (most active, larger developments)

Assuming the GIT command line client is installed, you can clone (get locally) the repository with the commands below.

Latest Stable (master branch, useless for development purposes, lives as maintenance moving forward)

git clone --recursive git://github.com/spring/spring.git -b master

To later update it (get the changes other people did) with:

git pull --rebase

Maintenance (maintenance branch)

git clone --recursive git://github.com/spring/spring.git -b maintenance

Bleeding-edge (develop branch)

git clone --recursive git://github.com/spring/spring.git -b develop

Working with git

Please note that patches to the code must be done for either develop or maintenance. Such patches can be then sent to one of the developers with repository access. If you are new to git and github, you may want to have a look at this guide to get you started.

Note: you can switch branches this way:<syntaxhighlight lang="bash">

  1. (optional) backup your current code changes

git stash

  1. switch branch

git checkout $MY_OTHER_BRANCH

  1. sometimes needed
  2. note, it deletes all your unstashed changes and all non-pushed commits on the new branch,
  3. but it doesn't delete untracked files.
  4. git reset --hard
  1. update/sync with remote repo

git pull --rebase

  1. (optional) if you want to apply the code changes backed-up in the first step
  2. git stash pop # reapplies your changes and DELETES the backup
  3. or
  4. git stash apply --index 0 # reapplies your changes and keep the backup (see `git stash list`)

</syntaxhighlight>

Submodules

To obtain the submodules you should clone the repository with --recursive as mentioned above. If you haven't done this, you can execute the following code <syntaxhighlight lang="bash"> git submodule sync git submodule update --init

</syntaxhighlight>

To update the submodules, you have to execute the same commands again or pull normally.

Compiling with MinGW

Requirements

install cmake and 7-zip and msysgit.

Installing MinGW

Compiling Spring in MinGW requires MinGW-W64

Download and run the "Mingw-builds project - native toolchains using trunk" installer from MinGW-w64.


Select the following options:

  • Version: Any version above 4.8.x should work, 4.9.x+ may not have been tested as thoroughly.
  • Architecture: i686
  • Threads: posix
  • Exception: sjlj This is the only setting which needs to be changed from the default
  • Build Revision: The latest one

Possible Problems

  • If you get undefined reference to `_Unwind_Resume' linking errors, deinstall whole MinGW and reinstall it with sjlj.
  • When you installed an old version of MinGW/TDM and forgot to deinstall it correctly, gcc.exe & g++.exe will be named gcc-dw2.exe/g++-dw2.exe. CMake will then fail to find the correct one, first try to deinstall anything mingw related and reinstall everything. If that didn't helped just rename the files. If even that doesn't help open cmake-gui and click the advanced button and set the paths to the correct files yourself (CMAKE_C_COMPILER & CMAKE_CXX_COMPILER).

Spring MinGW Dependencies (mingwlibs)

You also need some Spring dependencies, prepackaged in the mingwlibs archive.

  • use git's bash (you find it in the right click context menu when clicking the folder), cd into your spring source dir
  • run git clone git://github.com/spring/mingwlibs.git
  • and update it from time to time with: git pull --rebase
  • Make sure you install the package in the checkout directory, so the path is: /spring/mingwlibs. If done right, it will look like:
    • */spring/
    • */spring/...
    • */spring/mingwlibs
    • */spring/rts
  • Note: if you install the package somewhere else (preferably outside of the source tree), and pass its location with the MINGDIR option to CMake in the configure step (see further down, in the quick instructions).

configure using CMake

  • run the cmake-gui and select a source and a build directory
  • configure and follow the instructions, and adjust variables to your needs (defaults are OK)
    • you may need to get pthreads from https://www.sourceware.org/pthreads-win32/ and set PTHREADSGC32 to pthreads/Pre-built.2/lib/x86/libpthreadGC2.a
    • you may need to set FREETYPE_LIBRARY manually, to /mingwlibs/dll/freetype6.dll
  • press Generate
  • open a console (cmd.exe), cd into your build directory
  • optional: for multi-threaded compilation, the mingw32-make part may differ on your system:
    set MAKE_COMMAND=mingw32-make -j2
    (use -j4 for 4 threads)
  • compile with:
    mingw32-make install-spring
  • compile just the engine (spring.exe) with:
    mingw32-make engine-legacy

Generating the AI Sources/Wrappers

you can either build the wrapper:

make Cpp-AIWrapper

or generate all sources, in case you don't need the binary:

make generateSources

Notes

You can still use Visual Studio 2012 as described below to edit the code. This is very useful because it allows excellent code navigation, and it highlights syntax errors and trivial mistakes before compiling.

For debugging mingw builds, you can aquire a windows build of gdb from http://www.equation.com/servlet/equation.cmd?fa=gdb

To start debugging, copy gdb.exe to your build output directory, and launch it with gdb spring.exe. You can supply command line arguments to spring.exe with gdb --args spring.exe myreplayfile.sdf

Compiling with Visual Studio (not officially supported!)

Visual Studio works only on Windows 7 and above!

General Visual Studio Notes

When developing using Visual Studio keep in mind:

  • It's experimental and not proved to compile or run!
  • Your VS build won't sync with GCC builds in multiplayer mode
  • AIs built with Visual Studio will work with the mingw32 release builds thanks to the C AI Interface, however this interface may change when newer releases are made
  • Running any non-LUA AI on VS built Spring will crash it

2012 (v11)

Install Visual Studio 2012 Express for Windows Desktop, Visual C++ Compiler November 2012 CTP, cmake, 7-zip and msysgit.


From the Startmenu run "VS2012 x86 Native Tools Command Prompt" and type:

set PATH=%PATH%;%PROGRAMFILES%\git\bin;%PROGRAMFILES%\cmake 2.8\bin\
git clone git://github.com/spring/spring.git
cd spring
git clone git://github.com/spring/vclibs11.git vclibs
cmake -G "Visual Studio 11" .

Now start visual studio & open Spring.sln. Select "engine-legacy" as default project, as AIs and ofter stuff are known to fail to compile on visual studio.

In the Project Properties, make sure to select the Microsoft Visual C++ Compiler Nov 2012 CTP.

Note: Visual Studio 2012 Express for Windows Desktop is for free, but requires a registration after 30 days (to get a free license).