compiling_for_windows.rst 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. .. _doc_compiling_for_windows:
  2. Compiling for Windows
  3. =====================
  4. .. highlight:: shell
  5. Requirements
  6. ------------
  7. For compiling under Windows, the following is required:
  8. - `Visual C++ <http://www.microsoft.com/visualstudio>`__, Visual C++
  9. Express compiler or Visual Studio Community (recommended) at least
  10. the 2010 version (10.0) up to 2015 (14.0). **Make sure you get a
  11. version that can compile for C++, Desktop**.
  12. - `Python 2.7+ <https://www.python.org/downloads/>`__ (3.0 is
  13. untested as of now). Using the 32-bits installer is recommended.
  14. - `Pywin32 Python Extension <http://sourceforge.net/projects/pywin32>`__
  15. for parallel builds (which increase the build speed by a great factor).
  16. - `SCons <http://www.scons.org>`__ build system.
  17. Setting up SCons
  18. ----------------
  19. Python adds the interpreter (python.exe) to the path. It usually
  20. installs in ``C:\Python`` (or ``C:\Python[Version]``). SCons installs
  21. inside the python install and provides a .bat file called "scons.bat".
  22. The location of this file can be added to the path or it can simply be
  23. copied to ``C:\Python`` together with the interpreter executable.
  24. Compiling
  25. ---------
  26. Start a Visual Studio command prompt (it sets up environment variables
  27. needed by SCons to locate the compiler and SDK). It should be called
  28. "Developer Command Prompt for VS2015" or similar. SCons will not be able
  29. to compile from the standard Windows "Command Prompt".
  30. Once inside the Developer Console, go to the root dir of the engine
  31. source code and type:
  32. ::
  33. C:\godot> scons platform=windows
  34. If all goes well, the resulting binary executable will be placed in
  35. ``C:\godot\bin\godot.windows.tools.exe``. This executable file
  36. contains the whole engine and runs without any dependencies. Executing
  37. it will bring up the project manager.
  38. Note for Godot 2.0+ if you are having issues:
  39. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. You might also find other command prompts in your VS installation. Make
  41. sure you do not use x64 Native or Cross Tools Command Prompts, because
  42. 64 bit version of the Visual C compiler can not compile Godot 2.0+, only
  43. the 32 bit (x86) **compiler** can. If you get compiler errors about
  44. ``_asm`` (assembly instructions) in theora, switch the command prompt
  45. (compiler if not using VS IDE). One more thing, 32 bit compiler can
  46. compile **both** 32 bit Godot and 64 bit Godot. The process is called
  47. cross compiling for different architectures.
  48. How to know which compiler SCons will use? Open your Developer Command
  49. Prompt (or whatever prompt you are using) and type in ``cl.exe``:
  50. If it says this, you're good to go (note x86 at the end):
  51. ::
  52. Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x86
  53. If it says (x64), wrong prompt/compiler, find the right one. If the
  54. prompt you are using can't find ``cl.exe``, you are using the standard
  55. Windows Command Prompt... find the right developer prompt.
  56. Development in Visual Studio or other IDEs
  57. ------------------------------------------
  58. For most projects, using only scripting is enough but when development
  59. in C++ is needed, for creating modules or extending the engine, working
  60. with an IDE is usually desirable. The visual studio command prompt calls
  61. a .bat file that sets up environment variables (vcvarsall.bat). To build
  62. the whole engine from a single command outside the command prompt, the
  63. following should be called in a .bat file:
  64. ::
  65. C:\path_to_sdk\vcvarsall.bat && scons bin/godot.windows.tools.exe
  66. **NOTE:** It seems the latest Visual Studio does not include a desktop
  67. command prompt (No, Native tools for x86 is not it). The only way to
  68. build it seems to be by running:
  69. ::
  70. "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" && c:\python27\scons p=windows
  71. (or however your VS and Scons are installed)
  72. Cross-compiling
  73. ---------------
  74. If you are a Linux or Mac user, you need to install mingw32 and
  75. mingw-w64. Under Ubuntu or Debian, just run the following commands:
  76. ::
  77. apt-get install mingw32 mingw-w64
  78. If you are using another distro, scons will check for the following
  79. binaries:
  80. ::
  81. i586-mingw32msvc-gcc
  82. i686-w64-mingw32-gcc
  83. If the binaries are named or located somewhere else, export the
  84. following env variables:
  85. ::
  86. export MINGW32_PREFIX="/path/to/i586-mingw32msvc-"
  87. export MINGW64_PREFIX="/path/to/i686-w64-mingw32-"
  88. To make sure you are doing things correctly, executing the following in
  89. the shell should result in a working compiler:
  90. ::
  91. user@host:~$ ${MINGW32_PREFIX}gcc
  92. gcc: fatal error: no input files
  93. Creating Windows export templates
  94. ---------------------------------
  95. Windows export templates are created by compiling Godot as release, with
  96. the following flags:
  97. - (for 32 bits, using Mingw32 command prompt or Visual Studio command
  98. prompt)
  99. ::
  100. C:\godot> scons platform=windows tools=no target=release bits=32
  101. C:\godot> scons platform=windows tools=no target=release_debug bits=32
  102. - (for 64 bits, using Mingw-w64 or Visual Studio command prompt)
  103. ::
  104. C:\godot> scons platform=windows tools=no target=release bits=64
  105. C:\godot> scons platform=windows tools=no target=release_debug bits=64
  106. If you plan on replacing the standard templates, copy these to:
  107. ::
  108. C:\USERS\YOURUSER\AppData\Roaming\Godot\Templates
  109. With the following names:
  110. ::
  111. windows_32_debug.exe
  112. windows_32_release.exe
  113. windows_64_debug.exe
  114. windows_64_release.exe
  115. However, if you are writing your custom modules or custom C++ code, you
  116. might instead want to configure your binaries as custom export templates
  117. here:
  118. .. image:: /img/wintemplates.png
  119. You don't even need to copy them, you can just reference the resulting
  120. files in the ``bin\`` directory of your Godot source folder, so the next
  121. time you build you automatically have the custom templates referenced.