Compiling for Windows
See also Exporting for Windows.
Requirements
For compiling under Windows, the following is required:
- Visual Studio Community, version 2017 or later. VS 2019 is recommended. Make sure to read “Installing Visual Studio caveats” below or you will have to run/download the installer again.
- MinGW-w64 with GCC can be used as an alternative to Visual Studio. Be sure to install/configure it to use the
posixthread model. - Python 3.5+. Make sure to enable the option to add Python to the
PATHin the installer. - SCons build system. Using the latest release is recommended, especially for proper support of recent Visual Studio releases.
Note
Scoop installed, you can easily install MinGW and other dependencies using the following command:
Note MSYS2 installed, you can easily install MinGW and other dependencies using the following command:scoop install gcc python scons make
For each MSYS2 MinGW subsystem, you should then run pip3 install scons in its shell. See also Getting the source. Introduction to the buildsystem.pacman -S mingw-w64-x86_64-python3-pip mingw-w64-x86_64-gcc \ mingw-w64-i686-python3-pip mingw-w64-i686-gcc make
Setting up SCons
To install SCons, open the command prompt and run the following command:python -m pip install scons
Defaulting to user installation because normal site-packages is not writeable, you may have to run that command again using elevated permissions. Open a new command prompt as an Administrator then run the command again to ensure that SCons is available from thePATH.python --versionandscons --versioninto a command prompt (cmd.exe).PATHenvironment variable after installing it, then check again. You can do so by running the Python installer again and enabling the option to add Python to thePATH.python -m pip install --upgrade scons.Installing Visual Studio caveats
C++ in the list of workflows to install. Custom installation instead of Typical and select C++ as a language there. Modify button. Running the installer from Add/Remove Programs will only give you a Repair option, which won’t let you install C++ tools.Downloading Godot’s source
Getting the source for detailed instructions.C:\godot. Warning To prevent slowdowns caused by continuous virus scanning during compilation, add the Godot source folder to the list of exceptions in your antivirus software. Virus & threat protection, go to Virus & threat protection setting and scroll down to Exclusions. Click Add or remove exclusions then add the Godot source folder.Compiling
Selecting a compiler
use_mingw=yesto the SCons command line. Note that MSVC builds cannot be performed from the MSYS2 or MinGW shells. Use eithercmd.exeor PowerShell instead. During development, using the Visual Studio compiler is usually a better idea, as it links the Godot binary much faster than MinGW. However, MinGW can produce more optimized binaries using link-time optimization (see below), making it a better choice for production use.Running SCons
cd) and type:
You can specify a number of CPU threads to use to speed up the build:C:\godot> scons platform=windows
C:\godot> scons -j6 platform=windows
-joption to any SCons command you see below. Note When compiling with multiple CPU threads, SCons may warn about pywin32 being missing. You can safely ignore this warning.C:\godot\bin\with the namegodot.windows.tools.32.exeorgodot.windows.tools.64.exe. By default, SCons will build a binary matching your CPU architecture, but this can be overridden usingbits=64orbits=32. This executable file contains the whole engine and runs without any dependencies. Running it will bring up the Project Manager. Notetarget=release_debug.use_lto=yes. As link-time optimization is a memory-intensive process, this will require about 7 GB of available RAM while compiling. Note Self-contained mode by creating a file called._sc_or_sc_in thebin/folder.Development in Visual Studio or other IDEs
For most projects, using only scripting is enough but when development in C++ is needed, for creating modules or extending the engine, working with an IDE is usually desirable.vsproj=yesparameter, like this:
Build button. If you need to edit the build commands, they are located in “Godot” project settings, NMAKE sheet. SCons is called at the end of the commands. If you make a mistake, copy the command from one of the other build configurations (debug, release_debug, release) or architectures (Win32/x64); they are equivalent.scons p=windows vsproj=yes
Cross-compiling for Windows from other operating systems
MinGW-w64, which typically comes in 32-bit and 64-bit variants. The package names may differ based on your distribution, here are some known ones:PATHenvironment variable:i686-w64-mingw32-gccx86_64-w64-mingw32-gcc
PATH(e.g./usr/bin), you can define the following environment variables to give a hint to the build system:
To make sure you are doing things correctly, executing the following in the shell should result in a working compiler (the version output may differ based on your system):export MINGW32_PREFIX="/path/to/i686-w64-mingw32-"export MINGW64_PREFIX="/path/to/x86_64-w64-mingw32-"
${MINGW32_PREFIX}gcc --version# i686-w64-mingw32-gcc (GCC) 6.1.0 20160427 (Mageia MinGW 6.1.0-1.mga6)
Troubleshooting
this bug, due to a default configuration lacking support for POSIX threading. You can change that configuration following those instructions, for 64-bit:
And for 32-bit:sudo update-alternatives --config x86_64-w64-mingw32-gcc<choose x86_64-w64-mingw32-gcc-posix from the list>sudo update-alternatives --config x86_64-w64-mingw32-g++<choose x86_64-w64-mingw32-g++-posix from the list>
sudo update-alternatives --config i686-w64-mingw32-gcc<choose i686-w64-mingw32-gcc-posix from the list>sudo update-alternatives --config i686-w64-mingw32-g++<choose i686-w64-mingw32-g++-posix from the list>
Creating Windows export templates
Windows export templates are created by compiling Godot without the editor, with the following flags:C:\godot> scons platform=windows tools=no target=release_debug bits=32C:\godot> scons platform=windows tools=no target=release bits=32C:\godot> scons platform=windows tools=no target=release_debug bits=64C:\godot> scons platform=windows tools=no target=release bits=64
<version>with the version identifier (such as3.1.1.stableor3.2.dev):
With the following names:%USERPROFILE%\AppData\Roaming\Godot\templates\<version>\
However, if you are using custom modules or custom engine code, you may instead want to configure your binaries as custom export templates here:windows_32_debug.exewindows_32_release.exewindows_64_debug.exewindows_64_release.exe
bin\directory of your Godot source folder, so the next time you build, you will automatically have the custom templates referenced.
