From BlenderWiki

Jump to: navigation, search

Compiling Blender with Cygwin/GCC for Windows

[edit] Installing Cygwin/GCC

Here are some basic instructions for building Blender for Windows using GCC under Cygwin. Please note that the resulting executable does not depend on Cygwin and can be distrubuted to machines that don't have Cygwin installed.

First thing that we need to do is download cygwin. You can find this at www.cygwin.com. Now start the setup.exe and select 'Install from internet'. Tell it what directory to install the packages to, and pick a mirror to download from.

[edit] Setting up Cygwin

At this point you will come to a long list of packages. Select the Packages listed below by clicking on the word "skip". If the package is selected for installation already, a version number will appear in its place. In this case proceed to the next package on the list.

Image:Cygwin_packages.jpg

Archive

  • zip

Devel <-- Opens up into a longer list

  • cvs
  • gcc
  • gcc-g++
  • gcc-mingw
  • gettext
  • gettext-devel
  • make

Interpreters

  • perl
  • python

Libs

  • w32api

After you have selected all the packages click 'Next', and you have a long time to wait. Visit Elysiun.com while the files download, or better yet, venture into society!

*Reminder*

Don't go crazy if the mirror you chose fails. If it does, Cygwin will save your package selection. However, if you click cancel, any progress you may have made will be lost and your downloads will start from scratch. Once you've picked another mirror click 'Next' until your download starts again.

[edit] Source Checkout

After the download is complete Cygwin automatically installs the packages for you. You are now ready to do a cvs checkout of the Blender source code.

The first step is to choose a folder where you would like the source code to be placed in. In this example we'll use "C:\bf-blender", however you can place the files wherever you want. Now the exciting part!


Step 1: Creating a home for your Blender sources If you have not already created the folder mentioned above, you can do so by opening Cygwin and typing the following commands:

cd C:/
mkdir bf-blender

If you created the directory before you started Cygwin you need only switch to it as shown here:

cd C:/bf-blender


Step 2: Logging into the CVS server Issue the following command to log into the Blender Foundation's CVS server. It should be typed as one line.

cvs -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender login

Press enter when you are prompted for a password.


Step 3: Downloading the Blender module The next step is to download the Blender module of the BF-Blender source. BF-Blender is the official source tree of the Blender Foundation. These commands should also be typed as one line.

cvs -z3 -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender 
co blender

It will take a few minutes for the entire module to be downloaded. Alternatively, if you wish to do a checkout of the Tuhopuu source, you would use the following command:

cvs -z3 -d:pserver:anonymous@cvs.blender.org:/cvsroot/tuhopuu 
co tuhopuu3


Step 4: Acquiring the libraries Blender relies on a small number of external libraries in order for it to compile. Some of these are specific to individual operating systems. To download the Windows libraries you need to do an additional checkout of the lib/windows directory as shown here:

cvs -z3 -d:pserver:anonymous@cvs.blender.org:/cvsroot/bf-blender 
co lib/windows

Again this command is meant to be typed on one line and depending on the speed of your internet connection it may take some time for the files to be downloaded.


Step 5: Preparing the build system To prepare the build system to use only the free tools provided by Cygwin we must set some environment variables. This is done by creating a file called "user-def.mk" in the Blender directory (In our example the path for this file would be "C:\bf-blender\blender\user-def.mk")and inserting the following line with notepad or your favorite text editor:

export FREE_WINDOWS=true

The same end result can be acheived by typing the following at the Cygwin prompt. This code should be typed as two individual lines.

cd C:/bf-blender/blender
echo 'export FREE_WINDOWS=true' > user-def.mk


Step 6: Compiling Blender Now it's finally time to build blender.

Here it comes! The longest command you'll have to type:

make

Wait patiently while it compiles and cross your fingers that you won't have any errors :)


Step 7: Using the executable After Blender has compiled, you can either type make release to create a zip file containing all of the necessary files for an installation, or find the .exe file that you've just created.

You can find it in C:\bf-blender\blender\obj\windows\bin

Don't forget, you can't run Blender in that folder. In order for it to run you need to put the .exe into a folder that contains the appropriate .dll files. After you've done that, run your freshly-compiled Blender! If you decided to use the "make release" command, you will find the zip file in "C:\bf-blender\blender\obj\windows" within a folder named after the current version of Blender. Grab that zip file and extract all of the files to the folder of your chosing and you're all set! Congrats! See Additional Notes for some ways to speed this process up, and for instructions to fix trouble with keyboard function in Cygwin.


[edit] Some final notes

  • The build will take a long time, even on a fast machine
  • The executable generated by gcc will generally be slower than an msvc++ generated executable at rendering, but the OpenGL speed should be about the same.
  • Sound is disabled
  • If you want to clean your sources issue a 'make clean' in the top blender directory. This is needed if someone makes a change to any file in the 'makesdna' folder.
  • If you want to update your sources when somebody has added a new awesome feature, you will want to go to the topmost blender directory and issue the following command: cvs -z3 update -P -d
  • This is a work in progress, so some things may not be working right or it may not support all of the cutting edge features.
  • You can make a debug executable using 'make debug'. The debug executable will be larger and slower that the regular executable, but when used with the gnu debugger (gdb) it can help debug a blender problem (for example, it can locate the line of code that caused blender to crash).


[edit] Additional Notes

Here are some things you can do to make your compiling easier and your commands easier to remember. Go to the Cygwin installation folder and find a file named ".bashrc". In Unix-style operating systems, files with "dots" before their name with no extension typically store configuration data. Cygwin, being an emulation of the Bash shell from Unix, has many of the same conventions. You should be able to find this particular file in Cygwin\home\(yourname). Open it up in a normal text editor of your choice.

As you can see there's a whole bunch of code in there. This file tells Cygwin what commands you have defined. Add these functions to the end of the file:


bfcd - changes directory to "C:\bf-blender\blender" This is required by all of the functions below so that you may type the command from any directory at the Cygwin prompt and it will automatically change the current working directory to the root Blender folder. You can also use it on its own to quickly switch to the Blender directory.

alias bfcd='cd c:/bf-blender/blender'


blenderupdate - updates sources to newest version. There are other ways to go about making updates quicker, but this is one thats simple to remember and is much easier in my mind!

function blenderupdate()
{
    bfcd;
    cvs -z3 update -dP;
    return;
}


blendermake - compiles Blender.

function blendermake() 
{
    bfcd;
    make;
    return;
}


blendermakeclean - cleans sources.

As mentioned earlier, if someone changes Blender's DNA, you must recompile from scratch by using make clean. If you don't, you run the risk of hitting crashes and saving corrupted .blend files.

function blendermakeclean()
{
    bfcd;
    make clean;
    return;
}


blendercopy - copies executable to folder with appropriate .dll's.

Now this is usefull! Remember Step 8? Well this does it for you! Just substitute "(folder path)" with the location of the folder where the .dll's already exist.

function blendercopy() 
{
    bfcd;
    cp c:/bf-blender/blender/obj/windows/bin/blender.exe c:/(folder path);
    return;
}


release - performs 'make release'.

function release() 
{
    bfcd;
    make release;
    return;
}


You can change the function names to whatever you like. For example you might want to make them smaller. Say, for instance, you thought blendercopy was too lengthy and preferred something like bfc (perhaps short for Bf-Blender copy) or you thought blendermake would be better off as bfmc (bf-blender make clean). Feel free to customize them as you wish as long as the alias name for changing the directory is consistent throughout.

Another time saver is to use 'make quicky' when possible. This command compiles *only* the files in the directory you specify, very useful if, for example, Ton commits a fix for a bug in source/blender/src. In this instance you would type the following, being sure you are in the Blender root directory:

make quicky="source/blender/src"


You will see that this works very quickly, as the name implies. If more than one directory has changed and you wish to compile all of them, simple separate them with spaces inside the quotation marks like this:

make quicky="source/blender/src source/blender/render/"


Broken Delete Key Fix: On occasion some installs of Cygwin don't have a correctly functioning set of Home, End, Delete keys. If you run into this same problem where pressing the Delete key results in a "~" symbol being output on your screen try the following, but be aware that adding mistakes to either of these files could have unexpected results:

Create a file named "inputrc" with no extension and save it in your "C:\Cygwin\etc" directory. Add the code below to the file:

"\e[3~":    delete-char

Once you've accomplished this small task, you'll need to add a line to the file named 'profile' in "C:\Cygwin\etc\". It has no extension and should stay that way:

export INPUTRC=/etc/inputrc

These lines tell Cygwin to load the inputrc file as a list of key bindings when Cygwin opens. If you have other keys that are mapped incorrectly and produce the wrong characters (or none at all) when pressed, you would probably be best off reading this. Its quite technical but it may help you solve your problem.


[edit] Getting Help

If you have problems, come by #blendercoders and #blendercompilers on irc.freenode.net or post questions to the "Compiling, Libraries, Modules" forum at Blender.org. There is also the very useful bf-committers mailing list, that you can subscribe to here: Bf-Committers mailing list (as a bonus you can get info about the most recent features that are coming down the pipe ...)

This said, the most common fix to a problem will probably involve installing an additional Cygwin package, so keep that Cygwin setup program close by...


Special credit goes to Chris Want for creating the source for this document. Thanks Hos!