Difference between revisions of "Compiling Inkscape on Windows 32-bit"

From Inkscape Wiki
Jump to navigation Jump to search
(→‎Compile the Build Tool: Limit ourselves to one working command line (that actually includes -fopenmp) that is verified compatible with all recommended versions of gcc)
Line 89: Line 89:
== Compile the Build Tool ==
== Compile the Build Tool ==

Now compile the build tool. (Try the following command one by one. if that command fails)
Now compile the build tool with the following command:

C:\src\inkscape\trunk> g++ buildtool.cpp -o btool
  C:\src\inkscape\trunk> g++ buildtool.cpp -o btool -fopenmp
  C:\src\inkscape\trunk> g++ buildtool.cpp -o btool -fopenmp
C:\src\inkscape\trunk> g++ -DNEED_GETTIMEOFDAY buildtool.cpp -o btool -fopenmp
The <code>-fopenmp</code> flag enables [https://gcc.gnu.org/wiki/openmp OpenMP] which allows to use parallel compilation threads when building Inkscape.

== Building Inkscape ==
== Building Inkscape ==

Revision as of 00:09, 9 March 2016

For 64 bit: see Compiling Inkscape on Windows 64-bit

Inkscape was originally written for Linux, but it has been ported to other platforms, including Windows. Since Windows is not POSIX compliant and doesn't have several features useful to developers (like package management), compiling Inkscape on Windows is more tedious than on Linux, but perfectly possible. To make it easier, we have compiled a package that contains all the libraries you need to build Inkscape. This reduces the effort of compiling Inkscape to: download and install 3 programs, download library package, download sourcecode, and you are ready to go.

Setting up the build environment

To develop Inkscape, you will need the following things:

  • Bazaar
  • PuTTY programs: puttygen.exe and pageant.exe
  • TDM's GCC (MingW): Please use exactly the version 4.6.1 32bit bundle installer and follow the instructions below. In the setup, Uncheck the [Check for updated files on the TDM-GCC server] when installing, or it will install a newer version. Newer versions (tdm-gcc-4.7+) introduce important changes in gcc and don't work with the current Inkscape devlibs (see developpers' list discussion).
  • Launchpad account

In order to build the installer (not needed for most developers):

Install the compiler

Run the TDM-MinGW installer:

  1. Install in a path that doesn't contain spaces. The path 'C:\mingw' is ideal beacuse it is currently set in the mingwenv.bat file (along with the location of devlibs).
    • TDM-MinGW's default install option may be to a different location. You will have to edit the mingwenv.bat file to point there.
    • If you install it into another path, set the environment variable MINGW_PATH to the TDM-MinGW installation directory, e.g. the one containing README-tdm-gcc.txt (right click My Computer -> Properties -> Advanced -> Environment Variables).
  2. Be sure to enable the "GCC -> openmp support" checkbox from the components list

Create your Launchpad account

You can skip this step (or do it later) if you just want to download the sources, but not submit your changes.

If you do not have an SSH public/private key pair to identify yourself:

  • run the program puttygen.exe to generate an SSH key
  • save both its parts.

Log into your Launchpad account, go to your profile page and add the public part of the generated key to the list of SSH keys. Run the program pageant.exe (you can add it to Autorun). A tray icon should appear. Right click it, select "Add Key" and pick the private key file you have just generated from the dialog. Note that you need to repeat this after every login whenever you want to access Launchpad.

Now set up Bazaar. First tell it who you are, then associate with your Launchpad account. You need to use the account name (e.g. johnq), not the display name.(John Q. Public).

C:\> bzr whoami "Your Name <your_real_email@example.com>"
C:\> bzr launchpad-login your_launchpad_account

Install the developer libraries

Check out Inkscape Devlibs into C:\devlibs. If you check them out elsewhere, set the environment variable DEVLIBS_PATH to the path where they are. Devlibs are a bundle of all the libraries needed to compile Inkscape. If you experience any problems, make sure you have an up to date copy of those libraries and an up to date checkout of Inkscape source. To reduce the size of the download, pass the --lightweight parameter.

C:\> bzr checkout --lightweight lp:inkscape-devlibs devlibs

To update devlibs:

C:\devlibs> bzr update

All Inkscape developers can commit to the devlibs trunk. Advanced information about Devlibs, mainy useful when you want to update them to newly released versions of upstream libraries, is available here: Inkscape Devlibs. You can see some infomation from launchpad:inkscape-devlibs and trunk/files.

Obtaining Inkscape source code

You can obtain released Inkscape source from a tarball. Since version 0.47 they are hosted on Inkscape's Launchpad page. There are ready-made installers provided, so there's usually little reason to compile the stable version yourself.

To obtain cutting edge code, check out Inkscape source from the Bazaar repository. You can also use the TortoiseBZR shell extensions to do this. The recommended way is to first create a shared repository, then check out the Inkscape branch into that shared repository. Using this setup, branching will be a lot faster.

C:\src\inkscape> bzr init-repo --rich-root .
C:\src\inkscape> bzr upgrade
C:\src\inkscape> bzr checkout lp:inkscape trunk

If you don't want to create any branches, you can skip the shared repository step.

C:\src> bzr checkout lp:inkscape

IMPORTANT: make sure that the path to your Inkscape source checkout does not contain spaces. Unix tools do not like them and you will end up with a lot of error messages about missing files.

Set Environmental Variables

First set up the environmental variables. You need to run mingwenv once per console session like this:

C:\src\inkscape\trunk> mingwenv

Or you can set the paths in the Windows system settings. Go to (Win 7):

Start->Control Panel ->System and Security->System->Advanced system settings->Advanced->Environment variables->System variables->New. Add these variable names and values:
DEVLIBS_PATH c:\devlibs
MINGW_PATH c:\mingw
MINGW_BIN c:\mingw\bin
PKG_CONFIG_PATH c:\devlibs \lib\pkgconfig

Also, edit the PATH variable, and add these if not already present:

After the Environment Variables are set in the Windows system settings, a restart is required.

Compile the Build Tool

Now compile the build tool with the following command:

C:\src\inkscape\trunk> g++ buildtool.cpp -o btool -fopenmp

The -fopenmp flag enables OpenMP which allows to use parallel compilation threads when building Inkscape.

Building Inkscape

Finally initiate the compilation. Get a coffee or take your dog out for a walk, because it will take a rather long time. If you have a multicore processor, add "-j 8" to use (for example) 8 parallel compilation threads.

C:\src\inkscape\trunk> btool -j 8

Once everything is done, there should be an inkscape directory that contains the Inkscape executable and libraries needed to run it.


If you have only changed a few files and want to rebuild, delete the inkscape directory and run btool again.

To rebuild from scratch, execute the following sequence of commands:

C:\src\inkscape\trunk> btool clean
C:\src\inkscape\trunk> btool

Dealing With Build Errors

Feel free to add any questions or answers you have in here;

Q - My firewall software (Comodo's Defense+ component or similar) stopped the process continuing to the next step in the build, because I wasn't there to permit an action and it timed out. What can I do?

A1 - The best thing is to disable stuff like Defense+ (put it in learning mode works) because it will stop any process that is not approved, and building makes new files which can't be approved before they're built. Disabling Comodo's Defense+ does not disable your firewall, either inbound or outbound, but just the part that scans every application for suspicious operations. Other firewalls etc may vary.

A2 - If that doesn't suit, often you can simply run btool again and wait for Defense+ (or similar) to ask for approval for the process, and it will then continue as normal with the build. But remember that approving all the processes involved in the build process once doesn't mean they will all slip through next time.

A3 - This is the more complex way to continue, but may help if you have problems with A2. If you know the stage the process was meant to be up to (look at the output in the command windows and compare to the stages in the build.xml file), you can start again from there.

You may see something like this in the command window;

    ## Target : link : link objects and library to create executable
    ---- task : rc
    ============ cmd ============
    windres -o build/inkres.o --include-dir=src src/inkscape.rc
    ---- task : link

This will likely be followed by an error message. This means you were at the link stage

Now simply type;

    ...>btool stage

Or in this case

    ...>btool link

And the build will continue from there.

After this, you will probably have to step through the remaining stages manually, one by one. The stages can include (see build.xml, where each stage is labelled 'target name="target"') init, touchabout, compile, java, lib, i18n, link, linkinkview, dist, dist-all, clean.

Q - How do I rebuild just one file.o file? For instance if one particular file has gone wrong, or I want to try patching just one part of the code.

A - To find the right command for building any particular file in Inkscape, just look in the compile.lst after you have used btool once. Search for the name of the particular file (eg: print.cpp) and you will find the command used to compile it. You'll need to paste this into a text file, remove any carriage reurns and then paste that onto the command line.

Q - After I patched a file, I left a backup of the old file in the same directory called Copy of{filename}.cpp. The compiler complains about this file when building and stops.

A - Do not leave anything with a suffix .cpp in the source directories, apart from the original (or patched) source files. The build tool will try to compile everything ending in .cpp and will complain. If you backup an old file in the same directory before patching, call it {filename}.cpp.old or similar.

Q - I think I followed the instruction above. What could have caused the compiling error like this for src/extension/internal/pdfinput/pdf-parser.cpp?

    src/extension/internal/pdfinput/pdf-parser.cpp:2248: error: no matching function for call to 'GfxFont::getNextChar(char*&, int&, CharCode*, Unicode [8], int, int*, double*, double*, double*, double*)'

Same error for line 2297 as well.

For more information

There is some old information on building Inkscape with either Mingw on Windows, or a cross-compiler on Linux, at http://inkscape.modevia.com/win32_inkscape_org/win32buildnotes.html and old files mey be http://inkscape.modevia.com/win32libs/

Creating an installer

To create the inkscape-$RELEASE-win32.exe setup package you need the NSIS installer on your PC. Get that from http://nsis.sf.net . You have successfully built Inkscape and everything is in the ...\inkscape\ directory. Open the ...\packaging\win32\inkscape.nsi using the NSIS program and compile the package. Sooo easy :-)

The new wix installer in the packaging\wix directory creates msi packages. You need the windows installer XML package; get it from here http://wixtoolset.org/. Follow the instructions in the README file in the packaging\wix directory. The installer scripts parse version information from the inkscape.rc file. The generated packed is named as:


Note about Unicode

The GTK stack depends on functions only present in NT-based Windows (2000 and later). Therefore, Inkscape code can assume that Unicode functions from the Windows API (like GetCommandLineW) are always present. Note however that you should use the GLib/GTK functions rather the Windows API whenever possible.

See also