From BlenderWiki

Jump to: navigation, search

This is how to build Blender from its SVN source using Microsoft compiler with SCons. Except if specifically noted you can use the free Microsoft Visual C++ Express instead of the full Microsoft Visual Studio.

Set up your local repository

Create a folder to store your copy of the Blender source code. This guide will assume it is C:\BlenderSVN. Then use either the command line or TortoiseSVN to download (checkout) the Blender source code and pre-compiled libraries.

Command line

Open command prompt window by hitting Windows+R, and then typing cmd, or by searching for it in the start menu.

At the command prompt type the following commands:

cd C:\BlenderSVN
svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/blender blender

This will checkout the source files to blender/


If you plan on building 32-bit binaries with Microsoft Visual Studio, checkout the precompiled library files by typing:

svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/windows  lib/windows

If building 32-bit binaries with MinGW, type:

svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/mingw32 lib/mingw32

This will checkout the libraries to lib/windows/ or lib/mingw32/ respectively.


If you are going to be compiling 64-bit binaries using Microsoft Visual Studio, do this instead for the libraries:

svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/win64 lib/win64

Otherwise if building 64-bit binaries with MinGW-w64, type:

svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/mingw64 lib/mingw64

Again, this will check the libraries out in lib/win64/ or lib/mingw64/ respectively.

TortoiseSVN

Right-click the C:\BlenderSVN folder and select SVN checkout from the menu. A window will appear. For the URL of the repository enter:

https://svn.blender.org/svnroot/bf-blender/trunk/blender

Then verify that the checkout directory is:

C:\BlenderSVN\blender

Repeat the above steps for:

  • Precompiled libraries (if building 32-bit with Visual Studio):
    Repository: https://svn.blender.org/svnroot/bf-blender/trunk/lib/windows
    Directory: C:\BlenderSVN\lib\windows
  • Precompiled libraries (if building 32-bit with MinGW):
    Repository: https://svn.blender.org/svnroot/bf-blender/trunk/lib/mingw32
    Directory: C:\BlenderSVN\lib\mingw32
  • Precompiled libraries (if building 64-bit with Visual Studio):
    Repository: https://svn.blender.org/svnroot/bf-blender/trunk/lib/win64
    Directory: C:\BlenderSVN\lib\win64
  • Precompiled libraries (if building 64-bit with MinGW-w64):
    Repository: https://svn.blender.org/svnroot/bf-blender/trunk/lib/mingw64
    Directory: C:\BlenderSVN\lib\mingw64

Updating your repository

To keep your local Blender source code up to date, you will need to do a SVN update once in a while. You can either do this from a command line, or using TortoiseSVN. The most convenient way of doing this is to make a batch file containing the SVN commands.

Command line

Create this batch (.bat) file in C:\BlenderSVN\:

For Microsoft Visual Studio 32-bit:

cd lib\windows
svn update
cd ..\..\blender
svn update
pause

For MinGW (32-bit):

cd lib\mingw32
svn update
cd ..\..\blender
svn update
pause

For Microsoft Visual Studio 64-bit:

cd lib\win64
svn update
cd ..\..\blender
svn update
pause

For MinGW-w64:

cd lib\mingw64
svn update
cd ..\..\blender
svn update
pause

Run this newly created .bat file whenever you want to update.

TortoiseSVN

Right click on the C:/BlenderSVN/blender folder and choose SVN Update. A TortoiseSVN window will appear listing the files that is updating.

Once the process is finished it will print Completed At Revision: xxxxx at the end of the list. Just click the OK button to dismiss the dialog.

Repeat the above steps with the C:/BlenderSVN/lib/windows, C:/BlenderSVN/lib/win64, C:/BlenderSVN/lib/mingw32, and/or C:/BlenderSVN/lib/mingw64 folders to update the precompiled libraries, depending on what build environment you use.

Command line TortoiseSVN

Note: obsolete information. Latest TortoiseSVN can use the above command line if command line tools are selected during installation

As with the command line SVN, create a batch (.bat) file in C:\BlenderSVN\:

TortoiseProc.exe /command:update /path:"C:\BlenderSVN\blender" /notempfile /closeonend:1
TortoiseProc.exe /command:update /path:"C:\BlenderSVN\lib\windows" /notempfile /closeonend:1
pause

For 64-bit:

TortoiseProc.exe /command:update /path:"C:\BlenderSVN\blender" /notempfile /closeonend:1
TortoiseProc.exe /command:update /path:"C:\BlenderSVN\lib\win64" /notempfile /closeonend:1
pause


Building Blender with Scons

Configure Options

Customization
This page is provided to get an idea about customization. Only customize these settings if you know what you are doing. The default configuration provided through SVN is suitable for building straight from SVN.


For building a 32-bit version of Blender, save the following text as C:\BlenderSVN\blender\user-config.py:

BF_BUILDDIR = 'C:\\BlenderSVN\\build\\win32-vc'
BF_INSTALLDIR = 'C:\\BlenderSVN\\install\\win32-vc'
WITH_BF_OPENMP = False
WITH_BF_JACK = False
WITH_BF_FFMPEG = True
WITH_BF_OPENAL = True
WITH_BF_ICONV = True
WITH_BF_SNDFILE = True
WITH_BF_SDL = True
WITH_BF_OPENEXR = True
WITH_BF_JPEG = True
WITH_BF_PNG = True
WITH_BF_TIFF = True
WITH_BF_COLLADA = True
WITH_BF_GAMEENGINE = True
WITH_BF_PLAYER = True
BF_DEBUG = False
BF_NUMJOBS = 1

If you are building a 64-bit version of Blender, use this as your user-config.py:

BF_BUILDDIR = 'C:\\BlenderSVN\\build\\win64-vc'
BF_INSTALLDIR = 'C:\\BlenderSVN\\install\\win64-vc'
WITH_BF_OPENMP = False
WITH_BF_JACK = False
WITH_BF_FFMPEG = True
WITH_BF_OPENAL = True
WITH_BF_ICONV = True
WITH_BF_SNDFILE = True
WITH_BF_SDL = True
WITH_BF_OPENEXR = True
WITH_BF_JPEG = True
WITH_BF_PNG = True
WITH_BF_TIFF = True
WITH_BF_COLLADA = True
WITH_BF_GAMEENGINE = True
WITH_BF_PLAYER = True
BF_DEBUG = False
BF_NUMJOBS = 1

You can change the settings in this file.

  • If you get linking errors, examine the message. You may be able to turn off an option, such as Jack, if you get errors related to that library.
  • If you installed pywin32 and have a multicore machine, set BF_NUMJOBS to the number of processor cores you have. This number is how many separate files will be compiled at once. If you have 4 processor cores, setting this option to 4 will make the process of building run almost 4 times faster.

Multiple custom configurations

You can tell the SCons build process to look for a different file than user-config.py to read settings from. You do this by specifying the path to the file with BF_CONFIG on the command-line. For example, using a config file called debugsettings.py in the root source directory would require:

python scons\scons.py BF_CONFIG=debugsettings.py

If you want to quickly test a new setting, you can give the option also on the command-line, for example:

python scons\scons.py BF_BUILDDIR=../mybuilddir WITH_BF_OPENEXR=0

This command sets the build directory to BF_BUILDDIR and disables OpenEXR support.


Compile using Visual Studio

Open the Visual Studio Command Prompt (NOT just the normal command prompt). This can be found by searching your start menu. If compiling for 64-bit, make sure to open the 64-bit prompt. Now add Python 2.7 to your path by typing:

set PATH=C:\Python27;%PATH%
Paths:
Modify the above based on where you installed Python 2.7. When you installed it, the installer may have already edited the PATH environment variable. Just enter PATH into a command prompt to see if Python is already in there. Do NOT enter the path in any quotes, as you may be tempted to so if the path contains spaces.
32-bit / 64-bit Python:
Choose a Python install which corresponds to the number of bits you are building. Match an n-bit build with n-bit Python.
Non-ASCII Characters:
You might encounter problems while compiling if your computer name or some environment variables contain non-ASCII character. For best results, avoid non-ASCII characters.


Now do:

cd C:\BlenderSVN\blender
python scons\scons.py

This will compile Blender. The output and executable (blender.exe) will be found in a folder under C:\BlenderSVN\install\, either in win32-vc or win64-vc.

If you need to rebuild from scratch, you can clean the intermediate files with this command:

python scons\scons.py clean
Cleaning a build:
The clean target will recursively remove everything under BF_BUILDDIR. Hence, never use an important directory for BF_BUILDDIR, like BF_INSTALLDIR

Troubleshooting

Compile errors with Visual Studio 2008 PRO

When you get compile errors with functions from the c++ std:: library then please make sure that you have the "Visual studio 2008 Service pack 1" installed besides your Visual Studio 2008 Pro installation.

Cycles And CUDA Binaries

Currently CUDA GPU Toolkit 4.2 is supported: https://developer.nvidia.com/cuda-toolkit-42-archive

If you want to build with cycles and CUDA binaries you also need to install Microsoft Visual Studio (MSVC) 2008 as well and run the build process from a MSVC terminal. This is needed because the CUDA compiler needs to use the MSVC compiler.

For 64-bit builds(such as MinGW-w64) the CUDA compiler will need the 64bit toolset. It is possible to get this without MSVC professional by downloading the Windows SDK (version 7.1 has a very buggy installation but 7.0 iso should work) Additionally, there's one other thing to change for a 64-bit system. Apparently the cuda compiler has a "hard-coded" directory for 64-bit compilers. To make the fix, copy the needed file "vcvars64.bat" and rename it to "vcvarsamd64.bat" as follows:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat

to

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat

(method copied from: http://stackoverflow.com/questions/2970493/cuda-linking-error-visual-express-2008-nvcc-fatal-due-to-null-configuratio ) Then you should be able to generate 64bit kernels from a MSVC terminal.


nvcc fatal

When building via mingw and Windows SDK, Cuda compiler could fail with following message(even for 64bit building):

nvcc fatal : Visual Studio configuration file 'vsvars32.bat' could not be found for installation at 'C:/Program Files/Microsoft Visual Studio 9.0/VC/bin/../../..'

to solve that problem, you need to copy 'vcvars32.bat' and rename it to 'vsvars32.bat' as follows:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat

to

C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat

(this workaround was taken from nvidia dev talk forum: https://devtalk.nvidia.com/default/topic/462599/vsvars32-bat-not-found-error-on-compiling-samples-with-vsvars32-bat/)



Fail to start release or builds from buildbot

Usually this means the Microsoft Visual Studio 2008 redistributable packages aren't installed in your system. They can be easily found at Microsoft's download center page.

If you've got PYTHONPATH environment variable pointing to an older version of Python, it'll lead to Microsoft Visual C++ runtime library failure. If you've got such kind of error message, check on your environment variables.

Missing DLL's With MinGW

If you get a popup when configuring CMake or running SCons that says

libgmp-10.dll not found

This is because the DLL MinGW installs is not in the path, resolve this by adding "C:\MinGW\bin" to you're PATH environment variable.

MinGW & Redistribution

MinGW uses a few DLLs deal with runtime libraries so if you bundle builds for others, copy libgcc*.dll and libstdc++*.dll from MinGW/bin next to your new Blender executable. If you build with OpenMP, libgomp.dll will also be needed. This will make the builds usable even for people who don't have MinGW or PATH setup correctly.

Fail to Initialize with MinGW

If you get this error, installing python may resolve this, even though Blender comes with python.

The application failed to initialize properly (.....)
Click on OK to terminate the application.

Debug Builds

Without MSVC 2008 installed you may get an error like this on launch.

The application failed to initialize properly (0xc9159992).
Click on OK to terminate the application.

This is because python32_d.dll needs MSVC 2008 installed to run. Both the Full version or Express will work.

So even if you build with MinGW or MSVC 2010, to run debug builds you need MSVC 2008.

MSVC Express Has No OpenMP support

If you build with MSVC Express you must disable OpenMP (which will make some parts of Blender not use multiple processors).

  • on SCons disable WITH_BF_OPENMP
  • on CMake disable WITH_OPENMP

SCons Environment Variable problem

If one ore more environment variable contains a value with non-ASCII characters you'll see an error message appear since r34956 (older revision will throw a UnicodeDecodeError exception). It looks like this:

D:\blenderdev\currentsvn>python scons\scons.py BF_CONFIG=graphicall_32b
scons: Reading SConscript files ...
================
 
 
@@ ABORTING BUILD @@
 
PROBLEM DETECTED WITH ENVIRONMENT
---------------------------------
 
 
A problem with one or more environment variable was found
Their value contain non-ascii characters. Check the below
list and override them locally to be ASCII-clean by doing
'set VARNAME=cleanvalue' on the command-line prior to
starting the build process:
 
USERNAME = Näthan
TESTVAR = ElNiño

You don't have to change the main environment, it's enough to override the offending variables for the session. You could create a .bat with the overrides, so it's easy to run it whenever you open a new VS command prompt.