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

From Inkscape Wiki
Jump to navigation Jump to search
(The information on this page is outdated. Please see '''Compiling Inkscape on Windows''' for the updated instructions.)
 
(95 intermediate revisions by 29 users not shown)
Line 1: Line 1:
See the [http://sourceforge.net/tracker/index.php?func=detail&aid=847856&group_id=93438&atid=604308 Win32 Build ticket] for some info.
{{Note|The information on this page is outdated. Please see '''[[Compiling Inkscape on Windows]]''' for the updated instructions.}}


=== Inkscape under Windows ===
'''For 64 bit: see [[Compiling Inkscape on Windows 64-bit]]'''<br />


Inkscape was originally written for Linux, but has been ported to other platforms, including Windows, through the work of a number of dedicated developers.
----


You can get pre-built binaries of the Windows releases (both stable and development) from the [http://www.inkscape.org/download/?lang=en Inkscape download page]
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==


=== Building Your Own Binary ===
To develop Inkscape, you will need the following things:
As well as getting a pre-built binary, you can also build your own. You may do this for fun, to learn about programming, or to help test or improve Inkscape.


Several steps are required to build your own binary, as follows;
* [http://wiki.bazaar.canonical.com/WindowsDownloads Bazaar]
* You need to download the source code
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY] programs: puttygen.exe and pageant.exe
* You will need to download and install the MinGW compiler
* TDM's GCC (MingW): Please use exactly the [http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/Previous/1.1006.0/tdm-gcc-4.6.1.exe/download 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 the [http://inkscape.13.x6.nabble.com/Compiling-on-Windows-7-x64-td4965465.html discussion on the developers' list]).
* You will also need the supporting libraries used by Inkscape
* Launchpad account
* If you wish to apply patches for bug-testing, you will also need to download the patch utility


In order to build the installer (not needed for most developers):
* [http://wixtoolset.org Windows Installer XML Toolset] for rencent msi builds
* [http://sourceforge.net/projects/nsis/files/NSIS%202/2.46/nsis-2.46-setup.exe/download NSIS 2.46]


==== Getting The Inkscape Source ====


Depending on which version of Inkscape you are trying to build, you can try one of the following options;
===Install the compiler===
Run the TDM-MinGW installer:
# Install in a path that doesn't contain spaces. The path 'C:\mingw' is ideal beacuse it is currently set in the <tt>mingwenv.bat</tt> 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 <tt>mingwenv.bat</tt> 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 <tt>README-tdm-gcc.txt</tt> (right click My Computer -> Properties -> Advanced -> Environment Variables).
# 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.


'''''For the 0.46 Release Branch:'''''
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.


This branch of the source is frozen for the 0.46 release. New features are not allowed in order to focus on bug fixing. This is what you need to test for bugs in the 0.46 release.
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).


To get it, you will need to use an [http://wiki.inkscape.org/wiki/index.php/WorkingWithSVN SVN program] to checkout the source code from;
C:\> bzr whoami "''Your Name'' <''your_real_email@example.com''>"
C:\> bzr launchpad-login "''your_launchpad_account''"


https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/branches/RELEASE_0_46_BRANCH
===Error messages using Bazaar===
If you are seeing this error message in your Windows console:


          Connected (version 2.0, client Twisted)
              bzr: ERROR: Connection error: Unable to authenticate to SSH host as
                <email address hidden>
              supported auth types: ['publickey']


Please make sure to check [https://help.launchpad.net/YourAccount/CreatingAnSSHKeyPair: Creating An SSH Key Pair] and make sure you setup your key pair correctly (pageant.exe, puttygen.exe and plink.exe).


'''''For the 0.47 Trunk:'''''
===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 <tt>--lightweight</tt> parameter.


This branch of the source is for ongoing development and includes new and experimental features not in the 0.46 release branch. It is slowly diverging from the 0.46 release branch, thus becoming progressivly less useful for testing bugs in the 0.46 release.
C:\> bzr checkout --lightweight lp:inkscape-devlibs devlibs


An easy way to get it is via Ishmal's SVN snapshots; http://inkscape.modevia.com/svn-snap/
To update devlibs:


Download the latest file (or earlier if testing bugs) and decompress it. It does not need to be in a particular place, so put it wherever is convenient for you.
C:\devlibs> bzr update


Alternately, you can use an [http://wiki.inkscape.org/wiki/index.php/WorkingWithSVN SVN program] to checkout the source code from;
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 [https://launchpad.net/inkscape-devlibs launchpad:inkscape-devlibs] and [http://bazaar.launchpad.net/~inkscape.dev/inkscape-devlibs/trunk/files trunk/files].


https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/trunk/
=== Obtaining Inkscape source code ===


==== Getting The Compiler & Libraries ====
You can obtain released Inkscape source from a tarball. Since version 0.47 they are hosted on [https://launchpad.net/inkscape Inkscape's Launchpad page]. There are ready-made installers provided, so there's usually little reason to compile the stable version yourself.


Ishmal also provides a complete set of compiler and libraries on his website. You can get all packages from http://inkscape.modevia.com/win32libs/.
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.


Before you download, check for the last versions. As of March 13 2008 those are:
C:\src\inkscape> bzr init-repo --rich-root .
* the mingw compiler version 4.2 http://inkscape.modevia.com/win32libs/mingw-4.2.1-071022-dw2.7z
C:\src\inkscape> bzr upgrade
* other libraries http://inkscape.modevia.com/win32libs/devlibs-2.12-080313.7z
C:\src\inkscape> bzr checkout lp:inkscape trunk


The configuration files expect the packages in specific directories:
If you don't want to create any branches, you can skip the shared repository step.
* the compiler C:\MINGW (referenced by mingwenv.bat)
* other libraries C:\DEVLIBS (referenced in build.xml used by buildtool)


==== Patching The Source Code ====
C:\src> bzr checkout lp:inkscape


'''''Getting the patch program'''''
'''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.


To patch the Inkscape source code, you can use the patch program. One of the best places to get it is from the GnuWin32 project;
== Building ==
=== Environment variables ===
Edit the file <code>mingwenv.bat</code> in the root directory of the Inkscape source to match you local paths. Most importantly the two lines:


http://gnuwin32.sourceforge.net/packages/patch.htm
<pre>
# Path to the Inkscape development libraries.
if "%DEVLIBS_PATH%"=="" set DEVLIBS_PATH=c:\devlibs


This page has binaries, source and documentation for patch. You can put the patch program wherever you like, as it works indepently from the compiler.
# Path to the MinGW installation. Note: MinGW does not work with white spaces in the path name.
if "%MINGW_PATH%"=="" set MINGW_PATH=c:\mingw
</pre>


'''''Patching'''''
should point to the folders containing MinGW and the inkscape-devlibs.


One way of patching a particular module of code is to copy that code into the patch directory, as well as the patch/diff file, and then after patching to copy the patched file back to the source directory. Note: there can sometimes be several code modules with the same name (eg: print.cpp is in three places, but all are different)
Whenever you want to build Inkscape open a command prompt (<code>cmd.exe</code>), change into the root directory of the Inkscape source and set the environment variables with the following command:


To do the actual patching, you will again need to be in a command window. To patch, type something like the following;
<pre>
    ...>patch --binary {''modulename''}.cpp {''modulename''}.cpp.patch
mingwenv.bat
You should now have a patched code module to copy back to the same spot in the source tree.
</pre>


'''''Notes:'''''
=== Compiling Inkscape using CMake ===
*The ''--binary'' switch is only necessary if the files contain the wrong sort of line endings. The [http://gnuwin32.sourceforge.net/packages/patch.htm GnuWin32 Patch page] notes the following; ''"On MS-Windows, the patchfile must be a text file, i.e. CR-LF must be used as line endings. A file with LF may give the error: "Assertion failed, hunk, file patch.c, line 343," unless the option '--binary' is given."''
* Requirements for patch are "''Win32, i.e. MS-Windows 95 / 98 / ME / NT / 2000 / XP / 2003 / Vista with msvcrt.dll and msvcp60.dll. If msvcrt.dll or msvcp60.dll is not in your Windows/System folder, get them from [http://support.microsoft.com/default.aspx?scid=kb;en-us;259403 Microsoft], or (msvcrt.dll only) by installing [http://www.microsoft.com/windows/ie Internet Explorer] 4.0 or higher.''"


==== Building The Binary ====
''Note: To significantly reduce the time needed for incremental rebuilds consider [[CMake#Using CMake with Ninja to build Inkscape|using CMake in combination with Ninja]].''


Before you begin, it might be an idea to temporarily lower the level of any over zealous firewall software like Comodo's Defense+, which is a great firewall, but asks for confirmation to allow every new process that runs. It might also be good to disable screen savers or other background programs that chew a lot of processor power when the computer is not attended. These programs can interfere with the build process, and cause you to have to start again.
Go to the directory containing your Inkscape source and create the build output directory. In example:


<pre>
mkdir build
cd build
</pre>


You will need to open a command window (DOS prompt) to build the binary. Go to the Start Menu, select Run, and then type command (or cmd). Now you need to step into the Inkscape source directory:
You can also create an out of source build anywhere else in your file system. Just make sure that you pass the correct path to the source code directory in the next step. Create the makefiles using CMake:
    ...\> cd ...\inkscape


Ishmal's SVN snapshots include some convenient tools to help Windows users build a binary. Firstly run the batch file that sets up the MinGW environment variables
<pre>
    ...\> mingwenv.bat
# Pass the path to the source code directory as a parameter.
cmake -G "MinGW Makefiles" ..
</pre>


Now, build the magic make replacement:
Start the build process. The compiled Inkscape.exe will be in bin directory afterwards:
    ...\> g++ buildtool.cpp -o btool
or, if you get errors about gettimeofday:
    ...\> g++ -DNEED_GETTIMEOFDAY buildtool.cpp -o btool


<pre>
# 2 is the number of parallel threads to use for compiling. Increase the number to utilize more of your available CPU cores.
mingw32-make -j 2
</pre>


Now you can start the build process by simply running btool.
''Note: The version of mingw32-make included in TDM GCC 4.6.1 (this is what you should be using when building 32-bit Inkscape) does not have jobserver support, yet. As CMake makes use of recursive make calls the <code>-j</code> option won't have any effect on the recursively spawned instances. You can work around this by executing <code>set MAKE=mingw32-make -j 2</code> before starting the compilation process (this will make each spawned instance use up to 2 jobs).''
    ...\> btool


Grab a coffee and find something else to do. On an AMD-64 3000+ 1Gb it takes about 70 minutes, but your mileage may vary. The build process can normally continue in the background while you're doing other stuff on your PC.
Collect all the needed files and create a selfcontaing directory in  <code>./build/inkscape/</code>:


If everything went well, you should now have you fresh Inkscape in the ...\Inkscape\Inkscape directory.
<pre>
mingw32-make install
</pre>
 
As cmake hides the actual compiler calls, here is a way how to see what make is doing.
 
<pre>
mingw32-make VERBOSE=1 -j 2
</pre>
 
; If something goes wrong
Execute the following commands from the <code>build</code> directory
<pre>
rm -r CMakeFiles
rm CMakeCache.txt
</pre>
and start with running CMake (see above) again.
 
; If something goes very wrong
Remove the <code>build</code> directory and start over.
 
=== Compiling Inkscape using btool (deprecated) ===
 
''Note: This method was the default up to Inkscape 0.91. It still works in 0.92 but compiling using CMake [[#Compiling Inkscape using CMake|as described above]] is the preferred option.''
 
Now compile the build tool with the following command:
 
C:\src\inkscape\trunk> g++ 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 ====
 
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 <tt>inkscape</tt> directory that contains the Inkscape executable and libraries needed to run it.
 
==== Rebuilding ====
 
If you have only changed a few files and want to rebuild, delete the <tt>inkscape</tt> directory and run <tt>btool</tt> 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 ====
==== Dealing With Build Errors ====
Write any questions or answers you have in here;
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?


Q - My firewall software (Comodo's Defense+ component) 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.


A1 - Often you can simply run btool again and wait for the firewall to ask for approval for the process, and it will then continue as normal with the build. This is the simplest way to continue.
'''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.


A2 - This is the more complex way to continue, but may help if you have problems with the easier way. 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.
'''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;
You may see something like this in the command window;
Line 131: Line 205:




Q - How do I rebuild just one ''file.o'' file? I tried deleting the compile.lst file in the root to force it to start again, hoping that it would skip all but that file.


Here's how I got into trouble. The build seemed to pause when I was away and the screen saver, or possibly the automatic defrag that triggers on low user activity, or something similar, activated. I saw that the last file built was made 3 hours ago, and I pressed CTRL-Z to stop the process, but it just stopped that one file and continued the overall process. I deleted the ''file.o'' file being worked on when I pressed CTRL-Z because it was huge, but the rest of the .o files seemed to have built normally. After that it gave errors and complained about line 200 in the build.xml file, which is the compile process.
'''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.


This could also be a relevant question if I want to try patching just one part of the code.
=== 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/


A - ??? Is this something like ''g++ module.cpp -o module.o'' and then put the file in the right place ???
== Creating an installer ==


==== For more information ====
There are currently two complementary methods:
We will update this page soon with information on how to build Inkscape on the Win32 platform. In the meantime,
* NSIS (Nullsoft Scriptable Install System), for creating an *.exe installer
there are some fairly complete notes on how to build the current package with either Mingw on Windows, or a
* WiX Toolset (Windows Installer XML Toolset), for creating an *.msi installer
cross-compiler on Linux, at


http://inkscape.modevia.com/win32_inkscape_org/win32buildnotes.html
NSIS provides a higher degree of freedom giving the .exe installer some advantages, notably translations, better component selection and smaller file size.


(note: http://inkscape.modevia.com/win32libs/ may have more complete and up-to-date library packages).
MSI however is the format preferred by many computer experts because it's a format standardized by Microsoft (i.e. it ''should'' always work) and facilitates administrative installation tasks.


=== Create the Setup package for Win32 ===
In the long run it would be desirable to have a single solution combining the advantages of both methods and preferably allowing to create *.exe and *.msi installers at the same time. Input and contributions are welcome!


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


In order to create an *.exe installer you need to download and install [http://nsis.sourceforge.net/ NSIS]. Starting with Inkscape 0.92 a Unicode installer is built, so you need at least NSIS 3.0 (which is the first version with official Unicode support).


==== A Note from Jon about UNICODE on Win32 ====
# Compile Inkscape as described above.
# You should then have a distribution directory containing all necessary files in either <code>…\inkscape</code> or <code>…\build\inkscape</code> sub-folder.<br/><small>At least this is where NSIS will be looking for it. If you have set-up paths differently define <code>INKSCAPE_DIST_DIR</code> in <code>inkscape.nsi</code> accordingly.</small>
# Compile the file <code>…\packaging\win32\inkscape.nsi</code> using NSIS (e.g. by right clicking the file and choosing "Compile NSIS Script").


Actually, Microsoft themselves never use _UNICODE, nor it's 'evil' friends TCHAR and _T.
Once finished compiling (to reduce compile time you can choose a compressor different from LZMA) you should have a brand-new Inkscape *.exe installer in the <code>…\packaging\win32</code> folders.
If it is used, it results in a binary that can not be run on Windows 95/98[[/ME]]. It is more of a "Windows NT only" define.


Microsoft applications like MS Office have been pure 16-bit Unicode internally for years now. Also remember that BSTRs in Win32 are required to have 16-bit Unicode data. So for any COM access on a Win32 box running Win9x[[/ME]] 'multibyte' or '8-bit' COM calls convert all ANSI data to Unicode once you pass things in. To avoid this, Microsoft just keeps data 16-bit Unicode and then translates to local ANSI codepage only when data needs to be passed directly to a Win32 call.
=== WiX Toolset (*.msi) ===


To help developers, Microsoft finally made public their API they had been using. It's [http://www.microsoft.com/globaldev/handson/dev/mslu_announce.mspx "The Microsoft Layer for Unicode"].
In order to create an *.msi installer you need to download and install the [http://wixtoolset.org/ WiX Toolset].


Although that simplifies things, it's not required. I've done Win32 programs that are 16-bit Unicode and run on Windows 95/98[[/ME]] with no problems years before they released that.
Step-by-step instructions can be found in the file [http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/view/head:/packaging/wix/README <code>…\packaging\wix\README</code>].


Soo.... _UNICODE can't be used as it makes your binary unusable on Win9x[[/ME]]. Then it turns out that TCHAR and _T can't be used either. (Oh, and MS can't really use them, since Office does run on Win9x[[/ME]]). So just explicitly use some 16-bit datatype for chars. Microsoft is misleading in their documentation when they state that wchar_t is 16-bit. Most other platforms (including Mac OS, Linux, Solaris, BSD, etc) follow the language standard's recommendation and make it 32-bit. So it is best to avoid wchar_t for any real cross-platform code.


So, some general guidelines are:
=== Windows store (*.appx) ===
* Never define _UNICODE
* Don't use _T
* Don't use TCHAR
* Don't use wchar_t
* Use some explicit 16-bit type for characters/strings
** [http://icu.sourceforge.net/ IBM's ICU] does this


So then it's a simple matter of converting data from the standard UTF-8 GTK+ data to UTF-16 data before passing to Win32-land.  
In order to upload the installer on [https://www.microsoft.com/fr-fr/store/p/inkscape/9pd9bhglfc7h the windows store], you need to use the [https://www.microsoft.com/fr-fr/store/p/desktop-app-converter/9nblggh4skzw desktop app converter] to create a .appx from the msi installer. The correct commandline is :


The result? A single binary that executes properly on both [[Win9X/ME]] and [[WinNT/2K/XP]], including full and proper font and filename support.
C:\src\inkscape\trunk> desktopAppConverter -Installer Inkscape-0.92.1-x64.msi -Destination C:/Users/Inkscape/SomeFolder/ -PackageName 25415Inkscape.Inkscape -Publisher CN=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -Version 0.92.1.0 -MakeAppx -AppDisplayName Inkscape -PackagePublisherDisplayName Inkscape -PackageDisplayName Inkscape -AppID Inkscape


And, as I've mentioned before, I've actually achieved this for a few different shipping products and projects.
The correct CN name can be found on the [https://developer.microsoft.com/en-us/dashboard/apps/overview windows developer admin panel] where you upload the package.


-- [[JonCruz|Jon C]]
== Note about Unicode ==


=== SVN and Windows ===
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.


If you want to access Inkscapes' subversion repository on SourceForge from Windows, I'd heartily recommend [[TortoiseSVN]].
=See also=
It has the SSH stuff built into it so you don't have to mess about with putty, and
*[[Compiling Inkscape]]
it integrates right into Explorer, so SVN becomes just an extension of the right-click file commands.
*[[Using Visual Studio]]
get it from http://tortoisesvn.net/


John
[[Category:Developer Documentation]]

Latest revision as of 19:03, 25 October 2017

Note: The information on this page is outdated. Please see Compiling Inkscape on Windows for the updated instructions.

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 the discussion on the developers' list).
  • 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"

Error messages using Bazaar

If you are seeing this error message in your Windows console:

         Connected (version 2.0, client Twisted)
             bzr: ERROR: Connection error: Unable to authenticate to SSH host as
               <email address hidden>
             supported auth types: ['publickey']

Please make sure to check Creating An SSH Key Pair and make sure you setup your key pair correctly (pageant.exe, puttygen.exe and plink.exe).

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.

Building

Environment variables

Edit the file mingwenv.bat in the root directory of the Inkscape source to match you local paths. Most importantly the two lines:

# Path to the Inkscape development libraries.
if "%DEVLIBS_PATH%"=="" set DEVLIBS_PATH=c:\devlibs

# Path to the MinGW installation. Note: MinGW does not work with white spaces in the path name.
if "%MINGW_PATH%"=="" set MINGW_PATH=c:\mingw

should point to the folders containing MinGW and the inkscape-devlibs.

Whenever you want to build Inkscape open a command prompt (cmd.exe), change into the root directory of the Inkscape source and set the environment variables with the following command:

mingwenv.bat

Compiling Inkscape using CMake

Note: To significantly reduce the time needed for incremental rebuilds consider using CMake in combination with Ninja.

Go to the directory containing your Inkscape source and create the build output directory. In example:

mkdir build
cd build

You can also create an out of source build anywhere else in your file system. Just make sure that you pass the correct path to the source code directory in the next step. Create the makefiles using CMake:

# Pass the path to the source code directory as a parameter.
cmake -G "MinGW Makefiles" ..

Start the build process. The compiled Inkscape.exe will be in bin directory afterwards:

# 2 is the number of parallel threads to use for compiling. Increase the number to utilize more of your available CPU cores.
mingw32-make -j 2

Note: The version of mingw32-make included in TDM GCC 4.6.1 (this is what you should be using when building 32-bit Inkscape) does not have jobserver support, yet. As CMake makes use of recursive make calls the -j option won't have any effect on the recursively spawned instances. You can work around this by executing set MAKE=mingw32-make -j 2 before starting the compilation process (this will make each spawned instance use up to 2 jobs).

Collect all the needed files and create a selfcontaing directory in ./build/inkscape/:

mingw32-make install

As cmake hides the actual compiler calls, here is a way how to see what make is doing.

mingw32-make VERBOSE=1 -j 2
If something goes wrong

Execute the following commands from the build directory

rm -r CMakeFiles
rm CMakeCache.txt

and start with running CMake (see above) again.

If something goes very wrong

Remove the build directory and start over.

Compiling Inkscape using btool (deprecated)

Note: This method was the default up to Inkscape 0.91. It still works in 0.92 but compiling using CMake as described above is the preferred option.

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.

Rebuilding

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

There are currently two complementary methods:

  • NSIS (Nullsoft Scriptable Install System), for creating an *.exe installer
  • WiX Toolset (Windows Installer XML Toolset), for creating an *.msi installer

NSIS provides a higher degree of freedom giving the .exe installer some advantages, notably translations, better component selection and smaller file size.

MSI however is the format preferred by many computer experts because it's a format standardized by Microsoft (i.e. it should always work) and facilitates administrative installation tasks.

In the long run it would be desirable to have a single solution combining the advantages of both methods and preferably allowing to create *.exe and *.msi installers at the same time. Input and contributions are welcome!

NSIS installer (*.exe)

In order to create an *.exe installer you need to download and install NSIS. Starting with Inkscape 0.92 a Unicode installer is built, so you need at least NSIS 3.0 (which is the first version with official Unicode support).

  1. Compile Inkscape as described above.
  2. You should then have a distribution directory containing all necessary files in either …\inkscape or …\build\inkscape sub-folder.
    At least this is where NSIS will be looking for it. If you have set-up paths differently define INKSCAPE_DIST_DIR in inkscape.nsi accordingly.
  3. Compile the file …\packaging\win32\inkscape.nsi using NSIS (e.g. by right clicking the file and choosing "Compile NSIS Script").

Once finished compiling (to reduce compile time you can choose a compressor different from LZMA) you should have a brand-new Inkscape *.exe installer in the …\packaging\win32 folders.

WiX Toolset (*.msi)

In order to create an *.msi installer you need to download and install the WiX Toolset.

Step-by-step instructions can be found in the file …\packaging\wix\README.


Windows store (*.appx)

In order to upload the installer on the windows store, you need to use the desktop app converter to create a .appx from the msi installer. The correct commandline is :

C:\src\inkscape\trunk> desktopAppConverter -Installer Inkscape-0.92.1-x64.msi -Destination C:/Users/Inkscape/SomeFolder/ -PackageName 25415Inkscape.Inkscape -Publisher CN=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -Version 0.92.1.0 -MakeAppx -AppDisplayName Inkscape -PackagePublisherDisplayName Inkscape -PackageDisplayName Inkscape -AppID Inkscape

The correct CN name can be found on the windows developer admin panel where you upload the package.

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