Building Spring on Windows: Difference between revisions

From Spring
Jump to navigationJump to search
Abma (talk | contribs)
Tulipe (talk | contribs)
m Another way added to fix some problems.
 
(75 intermediate revisions by 11 users not shown)
Line 3: Line 3:
   code * {margin:inherit;}
   code * {margin:inherit;}
}}
}}
= Get the Source Code =
{{Obtaining_The_Source_Code}}


=Compiling with MinGW+CMake=
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]].
Compiling Spring in MinGW requires >=GCC 4.x.
 
<span class=warning>Warning:</span> Compiling Spring on Windows often causes problems, it is heavily recommended to use [[Building_Spring_on_Linux|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)
 
That said, if you do wish to use Windows, the best place to get real-time help is the #sy lobby channel, or #sy on [[IRC]].
 
=Compiling with MinGW=
 
 
== Requirements ==
Install [http://www.cmake.org/ CMake] and [http://msysgit.github.io/ msysGit] and MinGW-w64:
 
When installing msysGit you should select the option to "Run Git from the Windows Command Prompt":
 
[[File:Msysgit6.png|400px]]
 
This is in order to automatically add Git to PATH making it easy for CMake to find.
 
== Installing 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.org/doku.php/download/mingw-builds], more specifically from here: [https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download]


==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|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. In 2020, version 8.1.0 works fine!
** core
* '''Architecture:''' i686
** g++
* '''Threads:''' posix
** openmp (optional)
* '''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>
== Adding to PATH ==


===Possible Problems===
Once installed, you should add the MinGW directory to your PATH variable so that Cmake can find the relevant binaries.  
* 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).


* 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>).
* Go to System properties (either via Control Panel\System and Security\System or by right clicking 'Computer' on the desktop), then click 'Advanced System Settings'.
* Click the 'Environment Variables' button at the bottom.
* Find Path in the 'System Variables' scrollbox, add an extra <code>;</code> to the end and then copy-paste in the MinGW directory (e.g. default is <code>C:\Program Files (x86)\mingw-w64\i686-4.9.1-posix-sjlj-rt_v3-rev0\mingw32\bin</code>).  
* Alternative instructions with images are easy to find online, for example [http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx here].


==Spring MinGW Dependencies (mingwlibs)==
= Get the Source Code =
You also need some Spring dependencies, prepackaged in the '''mingwlibs''' archive.


You can download a tarball [http://github.com/spring/mingwlibs '''here'''] ('''Download Source''' button).<br>
* use git's bash (you find it in the right click context menu when clicking the folder), <code>cd</code> into your spring source dir
Or (recommended) use git:
* open a console (cmd.exe) or use git's bash (you find it in the right click context menu when clicking the folder), <code>cd</code> into your source dir
* make a dir named mingwlibs
* <code>cd mingwlibs</code>
* run <code>git clone git://github.com/spring/mingwlibs.git</code>
* and update it from time to time with: <code>git pull --rebase</code>


===mingwlibs install directory===
<code><pre>
There are two ways to setup the MinGW libraries:
git clone --recursive git://github.com/spring/spring.git -b develop
cd spring
git clone https://github.com/spring/mingwlibs
</pre></code>
 
* update it from time to time with: <code>git pull --rebase</code>


* Make sure you install the package in the checkout directory, so the path is: /spring/mingwlibs. If done right, it will look like:
* Make sure you install the package in the checkout directory, so the path is: /spring/mingwlibs. If done right, it will look like:
Line 55: Line 70:
** */spring/rts
** */spring/rts


* 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).
* 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).
 


== Installing CMake ==
== configure using CMake ==
First get [http://www.cmake.org/cmake/resources/software.html CMake here] and install it.
 
Note, as of 2020, cmake-3.10.1-win64-x64.msi from https://cmake.org/files/v3.10/ works, 3.18 has issues detecting zlib.


then
* run the ''cmake-gui'' and select a source and a build directory
* 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)
* press '''Configure''' and follow the instructions
* specify native compilers by entering the paths to gcc.exe and g++.exe from your mingw64-builds directory
* if you wish to build the full portable version (install-spring), then make sure to set the CMAKE_INSTALL_PREFIX as well
* In case of configuration errors make sure AI_TYPES variable is set to NONE (default is ALL). This should remedy the issues press '''Configure''' again (Remark: Setting NATIVE works as well (tested in commit 9108cae116))
* This is where you can specify the build type, REL for release, DEBUG for debug build, and RELWITHDEBINFO for a mix
* press '''Generate'''
* press '''Generate'''
* open a console (''cmd.exe''), ''cd'' into your build directory
* open a console (''cmd.exe''), ''cd'' into your '''build''' directory
* ''optional:'' for multi-threaded compilation, the ''mingw32-make'' part may differ on your system: <code>''<pre>set MAKE_COMMAND=mingw32-make -j2</pre>''</code>
* ''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). For codeblocks configure CMAKE_CODEBLOCKS_MAKE_ARGUMENTS as -j4
* 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-legacy</pre>''</code>


===Generating the AI Sources/Wrappers===
===Generating the AI Sources/Wrappers===
Line 78: Line 99:
<code>make generateSources</code>
<code>make generateSources</code>


=Compiling with Visual Studio=
===Possible Problems===
* If you have successfully compiled but don't have an ingame graphical user interface and no widgets working, you could try downloading and compiling from the maintenance branch instead develop.
<code>
git clone --recursive git://github.com/spring/spring.git -b maintenance
</code>
 
* 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>).
 
 
=== 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!)=
Currently Visual Studio lacks some c++ features it doesn't compile spring!


==General Visual Studio Notes==
==General Visual Studio Notes==
When developing using Visual Studio keep in mind:
When developing using Visual Studio keep in mind:
*<span class="warning">It's experimental and not proved to compile or run!</span>
*<span class="warning">Your VS build won't sync with GCC builds in multiplayer mode</span>
*<span class="warning">Your VS build won't sync with GCC builds in multiplayer mode</span>
*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
*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
*Running any non-LUA AI on VS built Spring will crash it
*Most spring developers use linux based environments, and the Visual Studio projects may be slightly out of date or missing files at any one time. Please contribute any changes or fixes you find back into the project
*The project files are in /spring/rts/build/vstudio'''''n'''''
*You need to install the VClibs library package that holds all the project dependancies and put this in the /spring directory from the github checkout or the zipped source. The VClibs packages are Visual Studio version specific, so choose the proper one. If done right, it will look like:
**/spring/
**/spring/installer
**/spring/rts
**/spring/... other dirs
**/spring/vclibs


===2012 (v11)===


to create the project file for visual studio 10, type:
Install [http://www.microsoft.com/visualstudio/eng/downloads#d-express-windows-desktop Visual Studio 2012 Express for Windows Desktop], [http://www.microsoft.com/en-us/download/confirmation.aspx?id=35515 Visual C++ Compiler November 2012 CTP], [http://www.cmake.org/ cmake], [http://www.7-zip.org 7-zip] and [http://msysgit.github.io/ msysgit].
<code><pre>
git clone git://github.com/spring/vclibs10.git vclibs
cmake -G "Visual Studio 10" .
</pre></code>


==2005 (v8)==
(possibly the free Express Edition)


* Install the [http://springrts.com/dl/vclibs/spring-vc8libs-v8.7z VClibs for VS2005].
* Install the [http://msdn.microsoft.com/directx/sdk/ DirectX SDK]
* Install the PlatformSDK. I got away with unchecking the parts of the PlatformSDK that were obviously not related (IIS, web stuff). Makes for a smaller download. Make '''sure''' the Platform SDK and DirectX SDK are in the VS search/include directories.
** Note that the most recent version of Platform SDK is called [http://www.microsoft.com/downloads/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505&displaylang=en Windows SDK].
* After installing them, open Visual C++. Click Tools >> Options >> Projects and Solutions >> VC++ Directories. Add these entries to the corresponding sections (paths just a reference, yours may be different):
**Include files:
***$(ProgramFiles)\Microsoft DirectX SDK (August 2007)\Include
***$(ProgramFiles)\Microsoft Platform SDK\include
**Library files:
***$(ProgramFiles)\Microsoft DirectX SDK (August 2007)\Lib\x86 (Might need \x64 on a 64-bit platform, I don't know.)
***$(ProgramFiles)\Microsoft Platform SDK\lib
* Open the solution. /spring/rts/build/vstudio8/rts.sln
* Start building (usually you want to select the Release with error catching build, debug is really too slow and is used only when you really know what you want to test)
* Select the working directory in the project properties, otherwise spring will not work correctly


=== Errors ===
From the Startmenu run "VS2012 x86 Native Tools Command Prompt" and type:
* <span class=warning>...\Windows\v6.0A\include\shlwapi.h(196) : error C2061: syntax error : identifier 'PCUITEMID_CHILD'</span> - wrong version of Platform SDK is used; go to Tools >> Options >> >> Projects and Solutions >> VC++ Directories and move the one that's causing this problem all the way down.


==2008 (v9)==
<code><pre>
(Standard or above Edition)
set PATH=%PATH%;%PROGRAMFILES%\git\bin;%PROGRAMFILES%\cmake 2.8\bin\
 
git clone --recursive git://github.com/spring/spring.git -b develop
It won't work out of the box, you need at least this hotfix from Microsoft: [http://support.microsoft.com/kb/946040 KB946040] or update using your Windows Update, as well as [http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=6922 Visual Studio 2008 Feature Pack].
cd spring
 
git clone git://github.com/spring/vclibs11.git vclibs
For the rest the Visual Studio 8 instructions should apply, mostly. You probably won't need to add Windows SDK path references as they should be present by default. Before compiling it's recomended to select "Release with error catching" solution configuration or it's MT variant.
cmake -G "Visual Studio 11" .
 
</pre></code>
You need the [http://springrts.com/dl/vclibs/spring-vc9libs-v5.7z vclibs for VS2008], and not the ones for Visual Studio 2005. The installation procedure is the same though.
 
Be aware that the project file isn't updated nearly as frequently as it should, so it's best to use the .vcproj file from VS8 build and VS2008 will automatically update it.


=== Errors ===
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.


* <span class=warning>...\rts\lib\assimp\code\STEPFile.h(58) : fatal error C1083: Cannot open include file: 'unordered_map': No such file or directory</span>
In the Project Properties, make sure to [http://stackoverflow.com/questions/13238408/variadic-template-in-vs-2012-visual-c-november-2012-ctp select the Microsoft Visual C++ Compiler Nov 2012 CTP].
You need to install [http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=6922 Visual Studio 2008 Feature Pack]. It's recomended to do so after a clean installation of VS2008 prior to installing SP1 and other updates. The linked installer only supports VS2008 Standard or above.
If you installed all updates prior to installing the feature pack, there's no guarantee that installation of feature pack will be successfull (''Installation on systems with Visual Studio 2008 Service Pack 1 (BETA) is not supported''), though it did seem to work.


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


The instructions for VS2008 should mostly work, but you need [http://springrts.com/dl/vclibs/spring-vc10libs.7z VCLibs for VS2010] instead.


[[Category:Compiling]]
[[Category:Compiling]]

Latest revision as of 14:53, 22 July 2020

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)

That said, if you do wish to use Windows, the best place to get real-time help is the #sy lobby channel, or #sy on IRC.

Compiling with MinGW

Requirements

Install CMake and msysGit and MinGW-w64:

When installing msysGit you should select the option to "Run Git from the Windows Command Prompt":

This is in order to automatically add Git to PATH making it easy for CMake to find.

Installing MinGW-w64

Download and run the "Mingw-builds project - native toolchains using trunk" installer from [1], more specifically from here: [2]


Select the following options:

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

Adding to PATH

Once installed, you should add the MinGW directory to your PATH variable so that Cmake can find the relevant binaries.

  • Go to System properties (either via Control Panel\System and Security\System or by right clicking 'Computer' on the desktop), then click 'Advanced System Settings'.
  • Click the 'Environment Variables' button at the bottom.
  • Find Path in the 'System Variables' scrollbox, add an extra ; to the end and then copy-paste in the MinGW directory (e.g. default is C:\Program Files (x86)\mingw-w64\i686-4.9.1-posix-sjlj-rt_v3-rev0\mingw32\bin).
  • Alternative instructions with images are easy to find online, for example here.

Get the Source Code

  • use git's bash (you find it in the right click context menu when clicking the folder), cd into your spring source dir
git clone --recursive git://github.com/spring/spring.git -b develop
cd spring
git clone https://github.com/spring/mingwlibs
  • 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

Note, as of 2020, cmake-3.10.1-win64-x64.msi from https://cmake.org/files/v3.10/ works, 3.18 has issues detecting zlib.

  • run the cmake-gui and select a source and a build directory
  • press Configure and follow the instructions
  • specify native compilers by entering the paths to gcc.exe and g++.exe from your mingw64-builds directory
  • if you wish to build the full portable version (install-spring), then make sure to set the CMAKE_INSTALL_PREFIX as well
  • In case of configuration errors make sure AI_TYPES variable is set to NONE (default is ALL). This should remedy the issues press Configure again (Remark: Setting NATIVE works as well (tested in commit 9108cae116))
  • This is where you can specify the build type, REL for release, DEBUG for debug build, and RELWITHDEBINFO for a mix
  • 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). For codeblocks configure CMAKE_CODEBLOCKS_MAKE_ARGUMENTS as -j4
  • 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

Possible Problems

  • If you have successfully compiled but don't have an ingame graphical user interface and no widgets working, you could try downloading and compiling from the maintenance branch instead develop.

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

  • 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).


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!)

Currently Visual Studio lacks some c++ features it doesn't compile spring!

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 --recursive git://github.com/spring/spring.git -b develop
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).