HOW-TO:Compile for Windows


 * Note: XBMC is open source (GPL) software and as so the source code is available for anyone to modify and/or compile (under the rules of the GPL).

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).
 * Visual C++ 2010 (express edition is fine). Higher version might require some adjustments.
 * Microsoft DirectX SDK dated August 2009 or later
 * Download the June 2010 version here
 * Git for Windows (latest version available is fine)
 * Nullsoft sciptable install system (required for buildsetup.bat)
 * Java Runtime Environment (JRE)
 * Download from here
 * 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: http://code.google.com/p/tortoisegit/

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.

$ 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)
 * You are using Windows XP

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.

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.
 * 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.
 * 1) Launch Git Bash and cd into Documents ($ cd Documents)
 * 1) Clone the new fork of XBMC locally ($ git clone git@github.com: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 git@github.com:garbear/xbmc.git
 * 1) 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.

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.
 * [[File:TortoiseGit.png]]
 * Sit back and eat a sandwich. Downloading the source could take around 20 minutes or more (expect about 200 MB).

Setting up the build Environment
To setup the build environment, several scripts must be called.
 * 1) DownloadBuildDeps.bat (located in the folder project\BuildDependencies).
 * 2) * 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.
 * 3) DownloadMingwBuildEnv.bat (also located in the folder project\BuildDependencies) to download the necessary items for building the ffmpeg libraries.
 * 4) buildmingwlibs.bat (in project\Win32BuildSetup). This will build the ffmpeg libraries.
 * 5) BuildSetup.bat (in project\Win32BuildSetup) ONLY if you would like to build a package ready to go. In this case, BuildSetup.bat automatically calls buildmingwlibs.bat for you. To debug, or to build in Visual Studio directly, follow next steps.
 * 6) 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.

Building the mingw-compiled dependencies
(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 buildmingwlibs.bat and change the line 'call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat' into the absolute path. For example: 'call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"'
 * 1) Execute buildmingwlibs.bat in "path\to\xbmc\project\Win32BuildSetup"

Building XBMC for Windows (DirectX)

 * 1) Run VC++ 2010 Express
 * 2) Load the XBMC\project\VS2010Express\XBMC for Windows.sln solution file.
 * 3) Choose the project to build:
 * 4) * Debug or Release (obviously Debug if you wish to actually do development work).
 * 5) * Choose DirectX (OpenGL is deprecated).
 * 6) Build the project

Running/Debugging XBMC from Visual C++ Express 2010
If you are compiling XBMC 13.0 Alpha 9 or later: If you are compiling XBMC prior to 13.0 Alpha 9:
 * Skip this section
 * To run XBMC from Visual Studio you need to set a variable so XBMC knows where to look for files.
 * Open up the XBMC project properties from the solution explorer.
 * Goto the Debugging settings and enter "XBMC_HOME=C:\Dev\XBMC" (without quotes) in the "Environment" field, where C:\Dev\XBMC is the path where your XBMC root is (containing language/skin/system/userdata folders etc.)
 * Additionally you may need to copy SDL dll's to run.
 * Copy *.dll from "project\Win32BuildSetup\dependencies" to the build directory, e.g. "project\VS2010Express\XBMC\Debug (DirectX)"


 * You should now be all set to start developing for XBMC and submitting those patches.

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-Revxxxxx-gl.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++ 2010 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.

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

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.

Compile error on Win8
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\"