From BlenderWiki
[edit] Introduction
For some reason (which I can resolve only through changing the source code), the project files as they are won’t build with both FFMPEG and Quicktime (the ffmpeg build commands are not currently included in the VC7 project files, but since it seems to have trouble building I will leave it out of this tutorial). After much effort in trying to fix this, I finally gave in and tried CMake. It worked. I’m still trying to work the kinks out and I will certainly post about how to build with CMake in the near future.
This is the method found to create a build from the free Microsoft Visual C++ 2005 Express Edition. It is geared for the CVS builds since I update this page as required when the CVS makes serious changes (for example, adding or removing pre-processor definitions or new features). You can use these instructions as a guide to build a release build (e.g. Blender 2.42a), though if you may have to tweak a few things to get a release build.
[edit] Pre-requisites
You will need the following:
- Visual C++ 2005 Express Edition (aka VC 8 or MSVC)
- Microsoft ® Windows Server® 2003 R2 Platform SDK Web Install -OR- Microsoft® Windows® Software Development Kit for Windows Vista™ and .NET Framework 3.0 Runtime Components
- DirectX SDK
- Quicktime SDK (Can be optional - see Quicktime section below)
Things to note:
- It is imperative that after installing Visual C++ 2005 Express, you follow these directions prior to starting the instructions below. It doesn't matter if step 5 works or not. If you have Windows x64 like I do, you will be required to use the x64 Platform SDK, but it won't cause any issues, just make sure you point VC to the right folders. Here are the full instructions referenced from the Microsoft site above:
Update the Visual C++ directories in the Projects and Solutions section in the Options dialog box. Add the paths to the appropriate subsection depending on which SDK you use:
Executable files: C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin Include files: C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include Library files: C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib
-OR-
Executable files: C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin Include files: C:\Program Files\Microsoft SDKs\Windows\v6.0\Include And C:\Program Files\Microsoft SDKs\Windows\v6.0\Include\gl Library files: C:\Program Files\Microsoft SDKs\Windows\v6.0\Lib
(For the latest SDK, remember to select the x86 libraries during installation so they are installed!)
AND
Edit the corewin_express.vsprops file (found in C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults) and Change the string that reads:
AdditionalDependencies="kernel32.lib"
to
AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"
If you've installed DirectX after VC then this next step will likely be done for you, but it's good to check. Here is the manual method: Update the Visual C++ directories in the Projects and Solutions section in the Options dialog box. Add the paths to the appropriate subsection:
Executable files: C:\Program Files\Microsoft DirectX SDK (%Date%)\Developer Runtime\x86 Include files: C:\Program Files\Microsoft DirectX SDK (%Date%)\Include Library files: C:\Program Files\Microsoft DirectX SDK (%Date%)\Lib\x86
- For the Platform SDK, you can install everything, but all you really need to install is the Microsoft Windows Core SDK > Build Environment component.
- For the DirectX SDK, you could download and install the entire thing, but all you need are the files that I mention below that will go into the PlatformSDK folder. Of course, the only other way to get the files from the ~500 MB installer (other than installing it) is to have them from another source.
- If the above instructions still result in a build error that is related to the SDK and DirectX files not being found (e.g. studio.h errors), here is a work-around:
Please note - this step is only necessary if you get SDK and DirectX build errors. Copy the Lib, Bin, and Include folders from the Windows SDK install folder into a folder called PlatformSDK in the Visual C++ directory (you will need to create this folder). I then copy the files from the Lib, Include, and the x86 folder of the Runtime (aka Bin) folders from the DirectX SDK into the PlatformSDK folder. See below:
DirectX and Windows SDK files in %Program Files%\Microsoft Visual Studio 8\VC\PlatformSDK\Lib DirectX and Windows SDK files in %Program Files%\Microsoft Visual Studio 8\VC\PlatformSDK\Include DirectX and Windows SDK files in %Program Files%\Microsoft Visual Studio 8\VC\PlatformSDK\Bin
[edit] Getting The Sources
[edit] Option 1: Tortoise CVS
Now we are ready to get the sources. I use the same method indicated in the Scons Refectoring page so you will need Turtle CVS just as described on the site. Then Go to Start Menu >> Control Panel >> System >> Advanced (Tab) >> Envoronmant Variables (button) >> System Variables scroll area double click on the PATH item. At the end of the existing path text add the following:
c:\Program Files\TortoiseCVS
The commands below (which you should type in a command prompt) make the folder c:\blender and populate it with the folders “blender” for the blender source code and “lib” for the windows spesific libraries. At the CVS password prompt you can just press enter. (Because this is an anonymous CVS)
mkdir c:\blender cd c:\blender cvs -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender login cvs -z3 -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender co blender cvs -z3 -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender co lib/windows
If you want the final release (for example 2.42a) instead of the CVS, you would use this:
mkdir c:\blender2.42a cd c:\blender2.42a cvs -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender login cvs -z3 -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender co -r blender-2-42a-release blender cvs -z3 -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender co lib/windows
[edit] Option 2: Direct Download
Acquire Blender source code and libraries - Download the ‘daily checkout’ tarball (~70MB) from here. - Extract it in such a way that five new directories are created under C:\build
C:\build\blender………………………(contains the actual blender sourcecode as of yesterday midnight) C:\build\lib……………………………(contains all the library files) C:\build\old……………………………(safe to delete) C:\build\CVSROOT.broken………(safe to delete) C:\build\CVSROOT.broken2………(safe to delete)
OPTIONAL INFO: If you want to build an official release, you can grab the more stable source code (~10MB, library files are not included) from here. Simply delete everything under C:\build\blender and then extract the tarball to the same directory. Building from the official release ensures the Blender you compiled is stable and relatively bug-free.
[edit] Getting Quicktime Working (Can Be Optional)
Now we need to make some edits to the sources we just got. First, let’s make Quicktime available. From the QuickTime 7 SDK install folder copy the Libraries folder and the CIncludes folders to the following locations in the sources (you’ll need to create the QTDevWin folder):
- %Your Blender Source Folder%/lib/windows/QTDevWin/Libraries
- %Your Blender Source Folder%/lib/windows/QTDevWin/CIncludes
Optional: If you rather not have Quicktime included in the build (you hate quicktime or you don't want or have the Quicktime SDK), you can remove it by opening the the blender solution file at %Your Blender Folder%\blender\projectfiles_vc7\blender\blender.sln and ensuring that "Blender Release" is selected from the toolbar. When you open an .sln file for the first time, VC will ask you to convert them. Hit the finish button to do so, then hit the Next button (I usually uncheck the check box on the following window which will skip what was changed being shown). In the BL_src, BL_imbuf, BRE_render, and blender project files property pages (right click on the project then go to the bottom to select properties) under configuration-> C++ -> Preprocessor and remove “WITH_QUICKTIME” from the Preprocessor Definitions. Then in the properties page of the blender project and go to configuration -> Linker -> Input, and under “Additional Dependencies” remove the quciktime library (qtmlClient.lib). Then, under the Linker -> General properties remove the following from “Additional Library Directories”: ..\..\..\lib\windows\QTDevWin\Libraries
[edit] Getting OpenEXR Working (Can Be Optional)
The VC7 project files (which we are converting from) automatically include OpenEXR. There is still a small issue VC8 has with the VC7 project file setup which is the library directory location. You will still need to go to Linker -> General properties add the following to “Additional Library Directories”:
..\..\..\lib\windows\openexr\lib_vs2005
and remove
..\..\..\lib\windows\openexr\lib
In case you get an compiling error, here is what you should check on. First, open the blender solution file at %Your Blender Folder%\blender\projectfiles_vc7\blender\blender.sln and ensuring that "Blender Release" is selected from the toolbar. When you open an .sln file for the first time, VC will ask you to convert them. Hit the finish button to do so, then hit the Next button (I usually uncheck the check box on the following window which will skip what was changed being shown). After you open the solution, open the properties (right click on the project then go to the bottom to select properties) of the BKE_blenkernel, BL_src, BL_imbuf, BRE_render, and blender project files and to each go to configuration-> C++ -> Preprocessor and add “WITH_OPENEXR” from the Preprocessor Definitions. Then in the properties page of the blender project go to configuration -> Linker -> Input, and under “Additional Dependencies” add.
Iex.lib Imath.lib IlmImf.lib Half.lib
Now we are all set to build!
[edit] Optimizing The Build (Optional)
If you want to optimize your build, you can either use MSCV to do it the win32-vc-config.py file in the %Your Blender Folder%\blender\config folder.
[edit] Using MSVC
Here are two flags that I have found dramatically decrease render times when used inside MSVC:
For /arch:SSE or /arch:SSE2 Open the project's Property Pages dialog box. Click the C/C++ folder. Click the Code Generation property page. Modify the Enable Enhanced Instruction Set property.
For /fp:fast Open the project's Property Pages dialog box. Expand the Configuration Properties node. Click the C/C++ folder. Click the Code Generation property page. Modify the Floating Point Model property.
Note that /fp:fast for the elbeem project in the intern solution will cause MSVC to crash. Keeping it at /fp:precise solves this issue. Similarly when building with /arch:SSE, the BL_src project in the blender solution will cause a crash if /fp:fast is set. Setting it to /fp:precise, resolves the issue.
I also advise using the /O2 flag, however this is usually on by default and you can check if it is by looking at the top of the Code Generation property page.
You will need to do these flag modifications to every project that allows these modifications (build_install_all in intern and extern don't have these options available). For the list of available flags check out the Microsoft Library.
[edit] Using Scons
You can also use Scons to set flags and build Blender using the MSVC compiler (cl.exe). First create a user-config.py (by copying win32-vc-config.py which is in the %Your Blender Folder%\blender\config folder), then place it in %Your Blender Folder%\blender\ folder and then tweak the CCFLAGS with MSVC recognized flags. You can also use this file to turn various aspects of Blender on or off (to be built or not built). You can then use Scons to build as described here but using:
cd %Your Blender Folder%\blender scons BF_TOOLSET=msvc BF_BUILDDIR=c:\b
Now on to building with MSVC.
[edit] Building
Quick note: When you open an .sln file for the first time, VC will ask you to convert them. Hit the finish button to do so, then hit the Next button (I usually uncheck the check box on the following window which will skip what was changed being shown). Once that's done, follow the below instructions:
[edit] Extern
If you are using converted project files from the Blender CVS, Verse will fail to build (there is an error in the extern build). This is because the dependencies are set wrong (i.e. verse_server relies on verse being built first but if it's not set to have verse build first there will be an error). In order to correct this, right click on the verse_server project in the extern solution, select Project Dependencies > Dependencies tab,uncheck ftgl_static_lib and check the verse project box (ensuring that it's the only thing checked). If extern still fails, right click on the verse project and go to Project Only then Rebuild only Verse. This will make the verse.lib which will then allow you to rebuild the extern solution. If you find you need to do this, right click the extern solution and go to Properties > Configuration Properties to ensure that verse is checked off as a project that will be built (they should all be checked).
Open %Your Blender Folder%\blender\extern\make\msvc_7_0\extern.sln. Select [Blender Release] in combo box on the top toolbar. Then build solution (F7).
[edit] Intern
Open %Your Blender Folder%\blender\intern\make\msvc_7_0\intern.sln. Select [Blender Release]. Build solution (F7).
[edit] Blender
Open %Your Blender Folder%\blender\projectfiles_vc7\blender\blender.sln. Select [Blender Release]. Build solution (F7).
The Blender release can now be found in %Your Blender Folder%\blender\bin\. This release requires either the x86, x64 and Itanium-based versions of Windows Server 2003 SP1, Windows XP SP2, Windows XP x64 Pro Edition, or Windows 2000 with version 2 of the .Net framework (since it installs the VC8 dlls). For a way to have Blender run on XP SP1 or machines that don't have version 2 of the .NET framework, see the first building tip below.
[edit] MSVC 8 Building Tips
With the instructions above, Blender can be built with no problems. But after the first build and with continued use, you may find that the build will fail or not take the optimizations you set. I have outlined below some cases when this might happen and what to do about it.
- You can run the build fine but it won't run on a different computer (you get an error when you run the build).
This is usually due to the Visual C and C++ runtime dlls not being located on the system that can't run the build. I think (but cannot yet substantiate) that if you have version 2 of the .NET Framework, you should be fine. In any case, if it doesn't run, you can do the following to make the runtime dlls get packaged with the Blender exe:
1) On the machine you have Express installed, create the following folder and subfolders in your \program files\microsoft visual studio 8\VC folder: redist\x86\Microsoft.VC80.CRT
2) Copy msvcr80.dll, msvcp80.dll , msvcm80.dll from \windows\winsxs\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd\ into the folder \program files\microsoft visual studio 8\VC\redist\x86\Microsoft.VC80.CRT
3) in the above Microsoft.VC80.CRT folder, create a new file named: Microsoft.VC80.CRT.manifest
4) Paste the following content into the above manifest file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright © 1981-2001 Microsoft Corporation -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable/>
<assemblyIdentity
type="win32"
name="Microsoft.VC80.CRT"
version="8.0.50727.42"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b"
/>
<file name="msvcr80.dll"/>
<file name="msvcp80.dll"/>
<file name="msvcm80.dll"/>
</assembly>
Make sure the version number matches the version number in the dll file description.
5) You could stop at number 4, but I copy this Microsoft.VC80.CRT folder to the same place as the blender and lib folder of the blender source so it's easier to write the path of the manifest file (as below).
6) Right click on the blender project file and go to Linker > Manifest file. In the Generate Manifest line select No. Then go to the Additional Manifest Dependencies line and path to manifest (e.g. ..\..\..\Microsoft.VC80.CRT\Microsoft.VC80.CRT.manifest). Build as usual.
- You update your source files.
If you update your source files, thereby over-writing (or deleting) the old ones that you used for your last build, all the project files that you had converted to VC8 format and added OpenEXR or optimization to will also be overwritten (or deleted) (you don’t always need to overwrite your library files, so I don’t do that often since I rather not re-add the Quicktime folder and files to it). You can avoid re-doing all the settings described in the instructions above (like optimization and OpenEXR) by saving the solution and project files before you over-write the old source code. That way, after you update the source files, you can just add your modified VC8 solution and project files to the sources and be on your way. One way you can do this is to zip up the .sln and .vproj files in the key folders (extern\make\msvc_7_0, intern\make\msvc_7_0, projectfiles_vc7\blender\, and the project files that you modified to get OpenEXR working) being sure to keep the file paths in the zip, then extract them back to the updated source code folder overwriting the old project files with your own. If you just zip the three groups of files in locations I mentioned, extract on top of the new source code, and open the projects, you will still get a request to convert the files to VC8. You should still do this as it will not remove the settings you have saved in the project files. This still happens because there are MSVC project and solution files in almost every folder. If you wanted to be really thorough, you could zip up every solution and project file keeping the file paths intact. That way, you will never be asked to do a conversion.
- If you have made a build with the source files and are going to rebuild for some reason (using different optimizations and/or adding OpenEXR and/or removing Quicktime).
If right after making a build, you were to build again (using the “Build Solution” command), it would be much quicker since VC is using the previous build folder to take shortcuts in the build process. Taking these shortcuts sometimes causes updates you have made to the VC files not to be updated in the build. In order to ensure this will not happen, I recommend building using the "Rebuild Solution command for extern, intern, and the blender solutions.
- Your build fails even though you’ve done a successful build recently.
1) In this situation, delete the build folders and the blender source folder (you can keep the library folder), and download new Blender source files.
OR
2) If you have done a successful build and then changed your optimization flags the build might fail due to MSVC crashing (an internal error has occurred blah blah blah). This is because some flag combinations just don't seem to work, for example, having no instructions set (no sse or sse2) and fp:fast set, MSVC will crash.







![[]](/skins/blender/open.png)
