PSA: Our Wiki software is being updated to the latest version to fix the ReCaptcha issue. We request that no edits be made until this banner is removed. The wiki is still available for research purposes. Thankyou.

# HOW-TO:Compile Kodi for Windows

 Development Compiling HOW-TO:Compile Kodi for Windows

## 1 Prerequisites

### 1.1 Software

Below is a list of the required software to complete a successful compile on Windows.

• An x86 computer with supported operating-system (Vista, Windows 7 x64/x32 bit and up should all work) installed
• Correctly installed graphics device-drivers from the manufacturer's website, (the latest is often the best choice).
• Kodi v16 and lower: Visual C++ 2013 (express edition is fine). Higher version might require some adjustments. You need at least update 2 to be applied to your installation, update 5 recommended
• Kodi v17 and up: Visual Studio 2015 (Community edition is fine). Higher version might require some adjustments. You need at least update 3 to be applied to your installation (see images 1 & 2 below)
• It's possible to use Visual Studio 2017 if you install some 2015 Tools as well (see image 3 below):
• select "Individual components" during install, then tick "Visual C++ tools for CMake" and "VC++ 2015.3 v140 toolset for Desktop (x86,x64)" - all other required components will be automatically installed.
• Install MSBuild 2015 "Visual C++ Build Tools 2015"
• When using Visual Studio 2015, make sure to select a custom setup during installation and select C++ tools and and the Windows 10 SDK:
• Install Windows SDK version 10.0.14393 as well.
• For building Kodi v17 and up using Windows 7 remove Windows SDK version 8.1.
• Microsoft DirectX SDK dated August 2009 or later (Obsolete with Kodi 16.0)
• Git for Windows 2.x
• Nullsoft scriptable install system (required for building the installer with buildsetup.bat)
• Java Runtime Environment (JRE)
• Add the path to the directory containing the java executable (java.exe) to your PATH environment variable see here
• A git client for Windows, for example TortoiseGit available here.
• Install CMake
• For debugging on Windows 10, install Graphics Tools. Press Win+I then System. > Apps & features -> Manage optional features -> Add a feature then select Graphics tools.

## 2 Git

Git is a distributed revision control system (think Subversion, but with a central repository for each person) help.github.com is a good place to familiarize yourself with basic Git usage.

### 2.1 $git clone command line This guide assumes a basic understanding of the command line and the Git commands The XBMC source code will be installed to C:/Users/Username/Documents. You should use a different directory (i.e. C:\XBMC) and adjust this guide accordingly if any of the following conditions are true: • Your Windows username has a space in it • You wish to use a different directory (no spaces) If you are familiar with cloning a repository from GitHub, then skip to the next section. Otherwise, these steps (based on the guide at http://help.github.com/forking) will get you up and running. Additionally, more information can be found at Git Usage. 1. Create a free GitHub account, generate a SSH key for yourself and set your user and email in git. 2. Visit the central XBMC project page and click the Fork button. This will put your own personal fork of XBMC in your list of public repos. 3. Launch Git Bash and cd into Documents ($ cd Documents)
4. Clone the new fork of XBMC locally ($git clone [email protected]:gituser/xbmc.git). Note the use of the fork's private URL. Sit back, as this will download about a gigabyte of data.$ git clone [email protected]:garbear/xbmc.git
Cloning into xbmc...
Enter passphrase for key '/c/Users/Garbear/.ssh/id_rsa':
remote: Counting objects: 468274, done.
remote: Compressing objects: 100% (111888/111888), done.
remote: Total 468274 (delta 351100), reused 467072 (delta 350219)
Receiving objects: 100% (468274/468274), 1022.39 MiB | 488 KiB/s, done.
Resolving deltas: 100% (351100/351100), done.
5. When your clone completes, you will have created a remote named "origin" that points to your fork on GitHub (not to the original XBMC repo). To keep track of the original XBMC repo, cd into the xbmc directory ($cd xbmc) and add another remote named "upstream" ($ git remote add upstream git://github.com/xbmc/xbmc.git). Note that upstream uses the public clone URL, so we can't push changes directly to XBMC.

### 2.2 TortoiseGit

• Before starting you must read the following page: Git Usage
• Right click in a directory of your choice and select Git Clone...
• Enter git://github.com/xbmc/xbmc.git for the Url.
Note: there are many ways to setup a local git repository. See Git Usage for more details or git tutorials on the internet for advanced uses.
• Enter a name (e:\Coding\Windows\xbmc for example) for the destination directory into Directory
Note: choose a path and destination directory with no space characters. Some build scripts can't handle them.

## 3 Setting up the build Environment

To setup the build environment, several scripts must be called. The scripts may fail if you have a space in the path to the bat files.
Even though not required for all scripts, using the Developer Command Prompt for Visual Studio is advised to ensure a proper PATH environment.

You now have the option to build Kodi v18 as either a 32 bit or 64 bit program. This requires separate directories as follows:

• The 32 bit build is located in the folder- tools\buildsteps\windows\win32
• The 64 bit build is located in the folder- tools\buildsteps\windows\x64

The following information applies to both versions:

• Note: If compiling on Win7 x32 edit the bat file to change line 26: from "set msys2=msys64" to "set msys2=msys32"
3. make-mingwlibs.bat This will build the ffmpeg and some other libraries. This might need to be "Run as administrator".
• Note: If compiling on Win7 x32 edit the bat file to change line 13: from "set msys2=msys64" to "set msys2=msys32"
• Note: Run this command using a Visual Studio Command Prompt (see step 4 below)
4. BuildSetup.bat (located in tools\buildsteps\windows\$ARCH) ONLY if you would like to build a package ready to go. To debug, or to build in Visual Studio directly, follow next steps. 1. extract_git_rev.bat - this optional script, also called by BuildSetup.bat, will show the git revision in the system information window. Except for production purposes, it isn't recommended that you run this script. For v17 and previous, use the following: 1. DownloadBuildDeps.bat (located in the folder project\BuildDependencies). • Unfortunately, there is no warning given if an archive fails to download. If you try to compile and get some errors about a header file missing, this could be the reason why. If a library fails to download, it is probably a result of the URI changing and a developer should be notified (for example, libcurl in r35685). If you can figure out which package is failing and are able to download it, then simply sticking it in project\BuildDependencies\downloads and running DownloadBuildDeps.bat again should get you past that obstacle. 2. DownloadMingwBuildEnv.bat (also located in the folder project\BuildDependencies) to download the necessary items for building the ffmpeg libraries. • Note: If compiling on Win7 x32 edit the bat file to change line 26: from "set msys2=msys64" to "set msys2=msys32" 3. make-mingwlibs.bat (in tools\buildsteps\win32). This will build the ffmpeg and some other libraries. This might need to be "Run as administrator". • Note: If compiling on Win7 x32 edit the bat file to change line 13: from "set msys2=msys64" to "set msys2=msys32" 4. BuildSetup.bat (in project\Win32BuildSetup) ONLY if you would like to build a package ready to go. In this case, BuildSetup.bat automatically calls make-mingwlibs.bat for you. To debug, or to build in Visual Studio directly, follow next steps. 1. extract_git_rev.bat - this optional script, also called by BuildSetup.bat, will show the git revision in the system information window. Except for production purposes, it isn't recommended that you run this script. ## 4 Building the mingw-compiled dependencies 1. Execute make-mingwlibs.bat in "path\to\xbmc\tools\buildsteps\win32" or "path\to\xbmc\tools\buildsteps\x64" depending on what you're trying to build (you can skip this step if you only want to create a Setup installer, as it is included in the installer build script)  If you run into a "cl: Command not found"-error make sure that you are running from the "Visual Studio Command Prompt". If you are still having problems, edit make-mingwlibs.bat (located in the parent folder of the arch folder) and change the line 'call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat"' into the absolute path. For example: 'call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\vsvars32.bat"'  For Visual Studio 2017 please ensure that you have "VC++ 2015.3 v140 toolset for Desktop (x86,x64)" installed, otherwise you will get a 'Command not found' error. ## 5 Building Kodi for Windows Since v17 (Krypton) the Visual Studio solution files are created by CMake, they are not in the git repo. For full details refer to https://github.com/xbmc/xbmc/blob/master/cmake/README.md#building-kodi For v16 (Jarvis) and older, simply open the Visual Studio solution in "project/VS2010Express/XBMC for Windows.sln". ## 6 Running/Debugging XBMC from Visual C++ Express 2013/2015 If you are using Windows 10 you need to install optional component : Graphic Tools 1. Press Win+I then System. > Apps & features -> Manage optional features -> Add a feature then select Graphics tools. ## 7 Additional hints If you want to do release builds for your personal use and/or testing, go into your source dir and browse into \project\Win32BuildSetup There are several batch files in there that provide the tasks doing the build. Use BuildSetup.bat to get it done for you. If you want to create the setup installer (i.e. XBMCSetup-20140603-43b8331-master.exe) you need to install the NSIS Installer ( http://nsis.sourceforge.net/Main_Page ) to your system. Please note that you still need to set up VC++ 2013 as mentioned above before you can use these batches. There are several minor (and major) issues that could come in your way to prevent you from doing a successful (release) build. Those are: - 1. getting multiple error messages telling that "git_rev.h" is missing while trying to compile a release build - 2. getting several error messages by windows that some dll files are missing while trying to create the textures for the default skins. - 3. getting build errors about a missing d3dx9.h file solutions: 1. The extract_git_rev.bat script ran into trouble. At this time two git clients are supported: msysgit and TortoiseGit. The directory containing git.exe or tgit.exe must be in the PATH environment variable in order to be recognized by the script. 2. Several dlls are involved in the process of creating texture.xbt for the default skins. Those are SDL.dll SDL_image.dll jpeg.dll libpng1.dll zlib.dll SDL_image.dll can be downloaded from http://www.libsdl.org/projects/SDL_image/ and the other libraries can be found in path\to\xbmc\project\Win32BuildSetup\dependencies. Make sure these libraries are accessible inside your %PATH% environment so the batch will find them e.g. set PATH=path\to\xbmc\project\Win32BuildSetup\dependencies;%PATH% 3. Make sure the DirectX SDK is installed. A reboot may be required before Visual Studio can use the SDK. 4. IF you see "'java.exe' is not recognized as an internal or external command" messages during building, edit tools\codegenerator\GenerateSWIGBindings.bat and edit java.exe to a absolute path. ## 8 Debugging a crash with a minidump If you have a minidump (*.dmp) file of XBMC crashing on Windows you can use Visual Studio to extract valueable information about the cause of the crash from it. There are two requirements for being able to load a minidump in Visual Studio 1. You need to have the Program Database file (*.pdb) of the build which crashes 2. You need to be able to install the build which crashes In the requirements mentioned above it's not enough to be able to compile a similar build with the same sources, it has to be the exact same build. For XBMC's nightly builds the PDB files are available from the same place where the XBMC installers can be downloaded. After you have installed the same build and downloaded both the PDB and the minidump file you need to copy the PDB file into the installation directory and rename it to "XBMC.pdb" (matching "XBMC.exe"). The location of the minidump does not matter. With a double-click on the DMP file it will open in Visual Studio. Either click on the "Set symbol paths" link in the "Minidump File Summary" view or go to Debug -> Options and Settings -> Debugging -> Symbols. In the "Symbols file (.pdb) locations" list add the path to XBMC's installation directory (where you also stored the PDB) and close the dialog with OK. Now click on the "Debug with Native Only" link and Visual Studio will start the debugger and jump to the location where XBMC crashed. If Visual Studio asks you for the location of a specific source (.cpp) file you need to point it to your local XBMC source code. Once in the debugger you will see on which line XBMC crashed and you can also inspect the variable values of the crash context. ## 9 Common setup issues ### 9.1 Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=14.0.0.0 If MSBuild does complain about missing v14 files you may miss to install MSBuild 2015. Check "C:\Program Files (x86)\MSBuild\": if C:\Program Files (x86)\MSBuild\14.0 is not existig you have to install MSBuild 2015 "Visual C++ Build Tools 2015" ### 9.2 "Microsoft.Cpp.Default.props" can't be found If you get the message that "Microsoft.Cpp.Default.props" can't be found there's probably a key missing in the registry. MSBuild uses the VCTargetsPath to locate default cpp properties but cannot because the registry lacks this key. Check for the key • Launch regedit • Navigate to HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersion\4.0 • Inspect VCTargetsPath key. The value should be "$(MSBuildExtensionsPath32)\Microsoft.Cpp\v4.0\"

To fix

• Launch regedit
• Navigate to HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersion\4.0
• Add string key VCTargetsPath key
• Set Value to "\$(MSBuildExtensionsPath32)\Microsoft.Cpp\v4.0\"