Difference between revisions of "MG/Windows Compiling"

From MegaGlest
Jump to navigation Jump to search
 
(35 intermediate revisions by 12 users not shown)
Line 1: Line 1:
 
This page explains how to compile [[MegaGlest]] for Windows.
 
This page explains how to compile [[MegaGlest]] for Windows.
  
==Compiling from source==
+
==Introduction==
#[[MG/Getting The Code|Get the project ]] from [[MG/SVN Structure|MegaGlest's subversion repository]] using the command line or your favorite subversion utility (such as [http://tortoisesvn.tigris.org/ TortoiseSVN]). If you are going to use subversion on 64-bit Windows 7 and get error messages like ''The file or directory is corrupted and unreadable'' then that's because your OS's only primary file system [http://glest.org/glest_board/?topic=5611.msg58480#msg58480 is buggy].
+
Generally, there are two approaches to get your work done:
#Download the [https://sourceforge.net/projects/megaglest/files/win32_deps.7z/download build dependencies archive].
+
*CLI: the automatable and fast one, using command line utilities and batch files
#Decompress (using [http://www.7-zip.org/ 7-zip]) the dependency archive into the folder named source. You should now see a <tt>win32_deps</tt> sub-folder with many files inside.
+
*GUI: the slow and shiny one, using graphical user interfaces
#Open the main solution in [http://www.microsoft.com/express/downloads/#2008-Visual-CPP Visual Studio] (it is recommended that VC++ 2008 '''WITH''' '''Service Pack 1''' be used, 2010 project files are also included and 'may' work but are not the primary environment used by megaglest developers) located in <tt>mk/windoze/Glest.sln</tt>
 
#Perform a rebuild project.
 
#If nothing goes wrong you will see <tt>megaglest.exe</tt> (and other binaries) in <tt>data/glest_game</tt> (where all the data content lives).
 
#To test the game, run the batch file <tt>CopyWindowsRuntimeDlls.bat</tt> located in <tt>mk\windoze</tt> to copy dependency dll's to the runtime binary folder.
 
  
==Windows Compiling in a Batch==
+
You have to choose one of them. The MegaGlest developers prefer the first approach, and this is also the most tested and recommended approach. You can of course choose the GUI approach, which ''should'' work, but please do not expect us to support you with setting up your VC++ build environment or GUI GIT client since this is hard to support and eats a lot of time. So if you choose this approach, please do not ask for support unless you do know how this is done properly and that the issues you are running into are clearly due to a bug in the solution files or this documentation.
[[File:SS_of_MG_Windows_Batch_File.png|thumb|MegaGlest batch file.]]
 
There is a convenient batch file (which assumes you have installed [http://www.sliksvn.com/en/download SlikSVN] for subversion command line use) which will:
 
  
#Update the branch you are working in with the latest subversion code
+
==Compilation==
#Touch the game_util.cpp file with the latest date/time
+
'''Prepare'''
#Compile all projects from command line
+
*Install [https://www.visualstudio.com/products/visual-studio-community-vs Visual Studio Community 2015] (or from [http://www.microsoft.com/en-us/download/details.aspx?id=48146 alternative download]) (or "better version" if you wish *) as well as any service packs available for it.
 +
Important note: Since version "2015" microsoft decided to (annoy people &) "make C++ optional" and hide it during installation so you should choose 'Custom' type of installation and then set check marks next to “Common Tools for Visual C++ 2015” and “Microsoft Foundation Classes for C++”.
 +
*Install [http://www.7-zip.org/ 7-Zip] or other compatible file archiving utility. 7-Zip is recommended.
 +
*Install and use [[MG/Getting_The_Code|''Git to check out'']] the MegaGlest source code.
 +
*Choose one approach.
  
This batch file exists within with <tt>mk\windoze</tt> folder and is called: <tt>build-mg.bat</tt>
+
===The CLI approach===
 +
''(recommended)''
 +
*Locate and run the batch file: [[File:SS_of_MG_Windows_Batch_File.png|thumb|MegaGlest batch file]] <tt>mk\windoze\build-mg-2015.bat</tt> (or build-mg32bit-2015.bat for 32 bit build) (Note: that it may be necessary to run this as an administrator, then right click on it and choose "run as administrator")
 +
*Note: On Windows 10 with Visual Studio 2017, running <tt>build-mg-2015.bat</tt> produces the following error: <tt>'msbuild' is not recognized as an internal or external command</tt>. To make the script work, it needs to be executed in the [https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs developer command prompt].
 +
*If nothing goes wrong you will see <tt>megaglest.exe</tt> (and other binaries) in <tt>mk\windoze\</tt>
 +
 
 +
===The GUI approach===
 +
*Read the above '''Introduction''' paragraph since it provides important information on the limits of this aproach
 +
*Update the branch you are working in with the [https://docs.megaglest.org/MG/Getting_The_Code#Update_the_source_code latest GIT code]
 +
*If it is first compilation download the build dependencies archive (which one and from where you can find out in the "code" of build-...bat script from CLI approach, some line with "wget.exe") and unpack it into the <tt>source</tt> subdirectory of your GIT working copy. You should then see a <tt>source\windows_deps...\</tt> directory with many files inside; ... then also run the <tt>mk\windoze\CopyWindowsRuntimeDlls_2015.bat</tt> batch file to copy runtime dependency DLL's to the runtime binary folder
 +
*Start Visual C++ 2015 and open the main solution, located in <tt>mk\windoze\Glest_vc2015.sln</tt>
 +
*Perform a rebuild project (choose <tt>release</tt> mode or <tt>release with debug info</tt>)
 +
*If nothing goes wrong you will see <tt>megaglest.exe</tt> (and other binaries) in <tt>mk\windoze</tt>
 +
 
 +
==Trouble shooting==
 +
===First compilation===
 +
''(The CLI approach)''
 +
 
 +
In the CLI approach a script <tt>mk\windoze\build-mg32bit-2015.bat</tt> should performs/ automates the following steps (listed on below list) for you:
 +
*Download and extract the build dependencies archive to <tt>source\windows_deps...\</tt> directory unless you already have it
 +
*On the first run, also run the <tt>mk\windoze\CopyWindowsRuntimeDlls_2015.bat</tt> batch file to copy runtime dependency DLL's to the runtime binary folder.
 +
*Update the branch you are working in with [https://docs.megaglest.org/MG/Getting_The_Code#Update_the_source_code the latest GIT code]
 +
*Update the timestamp and revision number on <tt>source\glest_game\facilities\game_util.cpp</tt>
 +
*Compile all projects from command line
 +
 
 +
When you know that steps and the error message then you can quite easy diagnose what is wrong, e.g. error during downloading may mean "broken internet connection" or "not enough disk space".
 +
 
 +
If error is related with <tt>7-zip</tt> then you should e.g. ensure that the <tt>7-zip</tt> command is available globally (add it to your PATH). If the installer did not automatically add the installation directory to the system path, instructions are available [http://www.computerhope.com/issues/ch000549.htm here]).
 +
 
 +
===Not first compilation===
 +
If your build fails, and you have not been building for a while, this is usually due to '''outdated build dependencies'''. Check them (which one archive and from where you should have you can find out in the "code" of build-...bat script from CLI approach, some line with "wget.exe") for <tt>windows_deps...7z</tt> when it was last updated, and if it's more recent than the one you have in <tt>source\</tt> (or if you are unsure), then recursively delete both <tt>source\windows_deps...\</tt> and <tt>source\windows_deps...7z</tt>. Deleting files recursively on Windows GUI can take ages, so to quickly delete recursively, do it on your command line''' after changing to the correct directory''' and choosing correct names:
 +
rd /Q /S source\windows_deps...\
 +
del /Q source\windows_deps...7z
 +
When using the GUI approach, you also need to manually download the updated build dependencies archive and extract it into the <tt>source\</tt> directory in your GIT repository. With the CLI approach, this will be done automatically on next build.
 +
 
 +
===Running===
 +
If MegaGlest crashes you should '''do a full rebuild'''. To do so with the CLI approach, instead of just running <tt>mk\windoze\build-mg32bit-2015.bat</tt>, to trigger a full rebuild run:
 +
mk\windoze\build-mg32bit-2015.bat n rebuild
 +
If you run into dependency errors when starting the game, be sure to re-run the <tt>mk\windoze\CopyWindowsRuntimeDlls_2015.bat</tt> batch file to copy possibly updated runtime dependency DLL's to the runtime binary folder.
 +
 
 +
==Reporting bugs==
 +
If you think you have run into a bug in MegaGlest, and neither reading the [http://readme.megaglest.org/ README] and [http://faq.megaglest.org/ FAQ] nor searching for it at http://bugs.megaglest.org helps, then please report a new bug at http://bugs.megaglest.org/ (one-time registration is neccessary to post).
 +
 
 +
When filing a bug, please provide a log of the build process of a '''full rebuild'''. With the CLI approach, run the build batch file and redirect all output to a '''log file''', such as by using:
 +
cd mk\windoze\
 +
build-mg32bit-2015.bat n rebuild 1>%Temp%\build-mg-2015.log 2>&1
 +
@echo The build log was written to: %Temp%\build-mg-2015.log
 +
The GUI approach will always do a full rebuild if you do it as described above.
  
 
==See also==
 
==See also==
Line 27: Line 72:
 
[[Category:MG]]
 
[[Category:MG]]
 
[[Category:Compiling]]
 
[[Category:Compiling]]
 +
[[Category:Development]]

Latest revision as of 22:10, 4 October 2017

This page explains how to compile MegaGlest for Windows.

Introduction[edit]

Generally, there are two approaches to get your work done:

  • CLI: the automatable and fast one, using command line utilities and batch files
  • GUI: the slow and shiny one, using graphical user interfaces

You have to choose one of them. The MegaGlest developers prefer the first approach, and this is also the most tested and recommended approach. You can of course choose the GUI approach, which should work, but please do not expect us to support you with setting up your VC++ build environment or GUI GIT client since this is hard to support and eats a lot of time. So if you choose this approach, please do not ask for support unless you do know how this is done properly and that the issues you are running into are clearly due to a bug in the solution files or this documentation.

Compilation[edit]

Prepare

Important note: Since version "2015" microsoft decided to (annoy people &) "make C++ optional" and hide it during installation so you should choose 'Custom' type of installation and then set check marks next to “Common Tools for Visual C++ 2015” and “Microsoft Foundation Classes for C++”.

  • Install 7-Zip or other compatible file archiving utility. 7-Zip is recommended.
  • Install and use Git to check out the MegaGlest source code.
  • Choose one approach.

The CLI approach[edit]

(recommended)

  • Locate and run the batch file:
    MegaGlest batch file
    mk\windoze\build-mg-2015.bat (or build-mg32bit-2015.bat for 32 bit build) (Note: that it may be necessary to run this as an administrator, then right click on it and choose "run as administrator")
  • Note: On Windows 10 with Visual Studio 2017, running build-mg-2015.bat produces the following error: 'msbuild' is not recognized as an internal or external command. To make the script work, it needs to be executed in the developer command prompt.
  • If nothing goes wrong you will see megaglest.exe (and other binaries) in mk\windoze\

The GUI approach[edit]

  • Read the above Introduction paragraph since it provides important information on the limits of this aproach
  • Update the branch you are working in with the latest GIT code
  • If it is first compilation download the build dependencies archive (which one and from where you can find out in the "code" of build-...bat script from CLI approach, some line with "wget.exe") and unpack it into the source subdirectory of your GIT working copy. You should then see a source\windows_deps...\ directory with many files inside; ... then also run the mk\windoze\CopyWindowsRuntimeDlls_2015.bat batch file to copy runtime dependency DLL's to the runtime binary folder
  • Start Visual C++ 2015 and open the main solution, located in mk\windoze\Glest_vc2015.sln
  • Perform a rebuild project (choose release mode or release with debug info)
  • If nothing goes wrong you will see megaglest.exe (and other binaries) in mk\windoze

Trouble shooting[edit]

First compilation[edit]

(The CLI approach)

In the CLI approach a script mk\windoze\build-mg32bit-2015.bat should performs/ automates the following steps (listed on below list) for you:

  • Download and extract the build dependencies archive to source\windows_deps...\ directory unless you already have it
  • On the first run, also run the mk\windoze\CopyWindowsRuntimeDlls_2015.bat batch file to copy runtime dependency DLL's to the runtime binary folder.
  • Update the branch you are working in with the latest GIT code
  • Update the timestamp and revision number on source\glest_game\facilities\game_util.cpp
  • Compile all projects from command line

When you know that steps and the error message then you can quite easy diagnose what is wrong, e.g. error during downloading may mean "broken internet connection" or "not enough disk space".

If error is related with 7-zip then you should e.g. ensure that the 7-zip command is available globally (add it to your PATH). If the installer did not automatically add the installation directory to the system path, instructions are available here).

Not first compilation[edit]

If your build fails, and you have not been building for a while, this is usually due to outdated build dependencies. Check them (which one archive and from where you should have you can find out in the "code" of build-...bat script from CLI approach, some line with "wget.exe") for windows_deps...7z when it was last updated, and if it's more recent than the one you have in source\ (or if you are unsure), then recursively delete both source\windows_deps...\ and source\windows_deps...7z. Deleting files recursively on Windows GUI can take ages, so to quickly delete recursively, do it on your command line after changing to the correct directory and choosing correct names:

rd /Q /S source\windows_deps...\
del /Q source\windows_deps...7z

When using the GUI approach, you also need to manually download the updated build dependencies archive and extract it into the source\ directory in your GIT repository. With the CLI approach, this will be done automatically on next build.

Running[edit]

If MegaGlest crashes you should do a full rebuild. To do so with the CLI approach, instead of just running mk\windoze\build-mg32bit-2015.bat, to trigger a full rebuild run:

mk\windoze\build-mg32bit-2015.bat n rebuild

If you run into dependency errors when starting the game, be sure to re-run the mk\windoze\CopyWindowsRuntimeDlls_2015.bat batch file to copy possibly updated runtime dependency DLL's to the runtime binary folder.

Reporting bugs[edit]

If you think you have run into a bug in MegaGlest, and neither reading the README and FAQ nor searching for it at http://bugs.megaglest.org helps, then please report a new bug at http://bugs.megaglest.org/ (one-time registration is neccessary to post).

When filing a bug, please provide a log of the build process of a full rebuild. With the CLI approach, run the build batch file and redirect all output to a log file, such as by using:

cd mk\windoze\
build-mg32bit-2015.bat n rebuild 1>%Temp%\build-mg-2015.log 2>&1
@echo The build log was written to: %Temp%\build-mg-2015.log

The GUI approach will always do a full rebuild if you do it as described above.

See also[edit]