HOW-TO:Compile for Windows
|Development||Compiling||HOW-TO:Compile for Windows|
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++ 2013 (express edition is fine). Higher version might require some adjustments. (Gotham and lower uses VS2010)
- Microsoft DirectX SDK dated August 2009 or later
- Download the June 2010 version here
- Git for Windows (latest version available is fine)
- Nullsoft scriptable install system (required for building the installer with buildsetup.bat)
- Java Runtime Environment (JRE)
- A git client for Windows, for example TortoiseGit available here: http://code.google.com/p/tortoisegit/
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.
- Create a free GitHub account, generate a SSH key for yourself and set your user and email in git.
- 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.
- Launch Git Bash and cd into Documents ($ cd Documents)
- Clone the new fork of XBMC locally ($ git clone email@example.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 firstname.lastname@example.org: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.
- 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.
- 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
- Sit back and eat a sandwich. Downloading the source could take around 20 minutes or more (expect about 200 MB).
3 Setting up the build Environment
To setup the build environment, several scripts must be called.
- 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.
- DownloadMingwBuildEnv.bat (also located in the folder project\BuildDependencies) to download the necessary items for building the ffmpeg libraries.
- make-mingwlibs.bat (in tools\buildsteps\win32). This will build the ffmpeg and some other libraries.
- 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.
- 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
- Execute make-mingwlibs.bat in "path\to\xbmc\tools\buildsteps\win32"
(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 and change the line 'call "%VS120COMNTOOLS%vsvars32.bat"' into the absolute path. For example: 'call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32.bat"'
5 Building XBMC for Windows (DirectX)
- Run VC++ 2013 Express
- Load the XBMC\project\VS2010Express\XBMC for Windows.sln solution file.
- Choose the project to build:
- Debug or Release (obviously Debug if you wish to actually do development work).
- Build the project
6 Running/Debugging XBMC from Visual C++ Express 2013
If you are compiling XBMC 13.0 Alpha 9 or later:
- Skip this section
If you are compiling XBMC prior to 13.0 Alpha 9:
- 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.
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
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.
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
- You need to have the Program Database file (*.pdb) of the build which crashes
- 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 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\"
- Launch regedit
- Navigate to HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersion\4.0
- Add string key VCTargetsPath key
- Set Value to "$(MSBuildExtensionsPath32)\Microsoft.Cpp\v4.0\"