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

From Inkscape Wiki
Jump to navigation Jump to search
m (moved Win32Port to Compiling Inkscape on Windows: more descriptive title)
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.
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.


=== Inkscape under Windows ===
==Setting up the build environment==


Inkscape was originally written for Linux, but has been ported to other platforms, including Windows, through the work of a number of dedicated developers.
To develop Inkscape, you will need the following things:


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]
* [http://www.7-zip.org/ 7-Zip]
* [http://wiki.bazaar.canonical.com/WindowsDownloads Bazaar]
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY] programs: puttygen.exe and pageant.exe
* MinGW compiler. Currently it's recommended to use this one: http://inkscape.modevia.com/win32libs/mingw-4.2.1-071022-dw2.7z Unpack it using 7-Zip to C:\mingw
* [http://nsis.sourceforge.net/Main_Page NSIS] 2.46
* Launchpad account


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.


=== Building Your Own Binary ===
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).
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 set things up before you can build your own binary, as follows;
C:\> bzr whoami "''Your Name'' <''your_real_email@example.com''>"
C:\> bzr launchpad-login ''your_launchpad_account''


1. You should install the TortoiseSVN program to help manage source files and patching (if you know how to do this without Tortoise, feel free)
Check out Inkscape Devlibs into C:\devlibs. 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. Currently you need to use the path mentioned above.


2. You need to download the Inkscape source code
C:\> bzr checkout lp:inkscape-devlibs devlibs


3. You will need to download and install the MinGW compiler and development libraries (devlibs) used by Inkscape
To update devlibs:


4. You will possibly want to patch the source code if testing bug fixes
C:\devlibs> bzr update


5. You are then able to build the Inkscape Binary
== Obtaining Inkscape source code ==


6. You may have to deal with some errors, but hopefully not...
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.


7. If you're keen, you can also generate an installation package for Windows
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 checkout lp:inkscape trunk


==== Install The TortoiseSVN 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.
The best way to get the source is straight from the SVN repository using the TortoiseSVN program. Follow these steps;


* Get TortoiseSVN from http://tortoisesvn.net/downloads
== Building Inkscape ==
* Install Tortoise SVN.


==== Download the Inkscape Source Code ====
Open the command prompt, navigate to the directory with Inkscape sources. First set up some environmental variables. You only need to do this once per console session.
'''''Setting up a local source repository:'''''
* Once Tortoise is installed, make a working folder wherever you want. It can be on a different partition if you wish - it doesn't matter.
* Inside the working folder, right click and select ''TortoiseSVN'' -> ''Create repository here''. This will make a bunch of folders inside your working folder.
* Now make another folder in the working folder called 0.46branch or whatever else you'd like to call it. This will hold the source files.


'''''Getting the source:'''''
C:\src\inkscape\trunk> mingwenv
* Enter the folder you created for the source files. Right click and select ''SVN Checkout''.
* Enter the URL for the source code you want;
** For the 0.46 release branch, use https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/branches/RELEASE_0_46_BRANCH/ (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.)
*** Someone has reported that to get this to work with the libraries above, they had to edit build-dw2.xml and build.xml and replace the instances (1 per file) of libpoppler-2.dll with libpoppler-3.dll. It compiles without the changes, but won't run. (Compiling/Running on Vista). This may have been corrected by now, so don't do this unless you have problems...
** For the 0.47 (or later) development branch (trunk), use https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/trunk/ (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 progressively less useful for testing bugs in the 0.46 release.)
* TortoiseSVN will now download the source files, which are just over 30Mb.
* To keep the source files up to date in future, simply right click on your working folder and select ''SVN update''.


'''''Notes:'''''
Now compile the build tool. Try the second command if the first one fails.
* You can also get a zipped up version of the trunk (0.47 dev) from Ishmal's site - http://inkscape.modevia.com/svn-snap/


==== Download The MinGW Compiler & Dev Libraries ====
C:\src\inkscape\trunk> g++ buildtool.cpp -o btool
C:\src\inkscape\trunk> g++ -DNEED_GETTIMEOFDAY buildtool.cpp -o btool


Thanks to Ishmal, it is extremely easy to set up your system to compile Inkscape. He has made a complete set of compiler and library files available from his website - http://inkscape.modevia.com/win32libs/.
Finally initiate the compilation. Get a coffee or take your dog out for a walk, because it will take a rather long time.


Before you download, check for the latest versions. As of '''Feb 26 2009''' those are:
C:\src\inkscape\trunk> btool
* The mingw compiler version 4.2.1 http://inkscape.modevia.com/win32libs/mingw-4.2.1-071022-dw2.7z
* The latest library SVN snapshot is http://inkscape.modevia.com/win32libs/devlibs-svn-0811161728.7z - this is currently just less than 120Mb
(you can optionally get the files completely using svn, located at https://svn.modevia.com/inkscape/devlibs - although this will be a significantly bigger download as the files are not compressed)


The configuration files expect the compiler and the development library files (devlibs) in specific directories:
Once everything is done, there should be an <tt>inkscape</tt> directory that contains the Inkscape executable and libraries needed to run it.
* Unzip the compiler (mingw-{version}.7z) to C:\MINGW (referenced by mingwenv.bat)
* Unzip the other libraries (devlibs-{version}.7z) to C:\DEVLIBS (must be this directory unless you want to edit the file build.xml used by buildtool)
* Once you have unzipped devlibs to C:\DEVLIBS make sure it is up to date with the latest svn version by running svn update. If you have TortoiseSVN installed this can be done by right-clicking on the devlibs folder and clicking ''SVN update''.


== Rebuilding ==


==== Patch The Source Code ====
If you have only changed a few files and want to rebuild, delete the <tt>inkscape</tt> directory and run <tt>btool</tt> again.


'''''Using TortoiseSVN:'''''
To rebuild from scratch, execute the following sequence of commands:
C:\src\inkscape\trunk> btool clean
C:\src\inkscape\trunk> btool


Tortoise makes patching quite easy. Follow these steps;
== Dealing With Build Errors ==
 
1. Find your patch. Windows Patches to the main SVN are now being kept in a folder under your main working directory called ''packaging\win32\patches''. If you download or make a subsequent patch, put it in this directory to keep things orderly. It should be called {patchname}.patch or {patchname}.diff
 
2. Right click on the patch, and select ''TortoiseSVN'' -> ''Apply Patch...''. Because the Windows patches are kept a little tucked away, Tortoise will probably give a message; '''The path {working directory}\packaging\win32\patches seems not to match the paths in the patchfile. But Tortoise found the path {working directory} matches it better. Do you want to use the suggested path instead?''' Click ''Yes'' to proceed.
 
3. Now comes the actual patching process. See the Tortoise website for an explanation of how to use the merge tool - http://tortoisesvn.net/docs/release/TortoiseMerge_en/tmerge-dug.html#tmerge-dug-open-view (see also the following pages)
 
4. Once patched, you will now notice that the patched file has a red exclamation rather than a green tick, as do its parent folders. This signifies that it has been altered from the SVN version, and helps you find altered files really quickly.
 
5. If you want to go back to the SVN version you originally ''checked out'', simply right click on an individual file or a whole folder and select ''TortoiseSVN'' -> ''Revert''. This will bring up a list of files that can be reverted. If you only selected one file, only that will be available to revert. If you selected a folder, all the modified files in that folder will be available to revert. Tick only those you wish to revert to the SVN version last checked out.
 
'''''Notes:'''''
* When applying several patches at once, you will possibly find that some patches update the same code modules. This is normal, and Tortoise can help you compare files and resolve conflicts. See the [http://tortoisesvn.net/docs/release/TortoiseMerge_en/tmerge-dug.html#tmerge-dug-open-view link mentioned above] to learn more.
* Sometimes conflicts are not able to be resolved using Tortoise, and you will need to edit the files by hand. Don't worry, you can always ''revert'' the files if you make a mistake. A good text editor to help is Notepad 2 - http://www.flos-freeware.ch/
* If you edit the source files yourself, Tortoise will register that the files are changed with an exclamation mark. To create your own patch from a changed file, right click on the ''src'' directory folder that contains your changed file, then select ''Tortoise SVN -> Create Patch''. Now tick only the file/s you edited and save the patch file. This can be posted to a bug report as a test, and possibly committed to SVN if your patch works.
 
 
 
 
'''''Using the GNU patch program:'''''
 
For those who love the command line, you can patch the hard way using the GNU patch program.
 
* Download the program from here  - http://gnuwin32.sourceforge.net/packages/patch.htm
* Put the patch program wherever you like, as it works independently from the compiler.
* If the patch file refers to the location in its header, put it in the /src directory and then patch, otherwise put it in the same directory as the file to be patched
* In a command window, type something like the following;
    ...>patch --binary {''modulename''}.cpp {''modulename''}.cpp.patch
* You should now have a patched code module to copy back to the same spot in the source tree.
* 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 patch file 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."''
 
==== Build The Inkscape Binary ====
 
Before you begin, it might be an idea to temporarily lower the level of any over zealous security software, 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.
 
 
'''''Doing A New Build'''''
 
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:
    ...\> cd ...\inkscape
 
Firstly run the batch file that sets up the MinGW environment variables
    ...\> mingwenv.bat
You can usually just type mingwenv (enter) and Windows will execute the batch file.
 
Now, build the build tool:
    ...\> g++ buildtool.cpp -o btool
or, if you get errors about gettimeofday:
    ...\> g++ -DNEED_GETTIMEOFDAY buildtool.cpp -o btool
 
 
Now you can start the build process by simply running btool.
    ...\> 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.
 
'''''Please note:''''' that the standard btool only builds Inkscape. In order to have Inkview included you must pass an additional parameter to btool:
    ...\>btool dist-all
 
If everything went well, you should now have you fresh Inkscape in the ...\Inkscape directory.
 
 
 
'''''Re-building after modifying source modules'''''
 
If you've already built the source once and done a few changes to source code files, you can do a quick rebuild using many of the files already compiled in the ''build'' directory. Only those that need to be rebuilt will be, and the ''btool'' program automatically figures that out. It will then 'link' the relevant files together and copy them into the ''inkscape'' directory.
 
To do a quick rebuild, simply go to the directory that contains the source and do the following;
 
* Delete or rename the ''inkscape'' directory, which contains the previous fully built and linked version of Inkscape
* Now open a command window and run the following;
    ...> mingwenv
    ...> btool dist-all
* Ishmal's build tool should now rebuild the individual files that have changed, along with any extra 'dependencies' these might require. If you've only applied one new patch, it can be done in less than 5 minutes!
 
 
'''''Note:''''' It is best not to do a quick rebuild if you have changed the version of libraries in C:\DEVLIBS. This can cause problems, as the files in the ''build'' directory incorporate functions from these libraries, which can change significantly between library versions. You will need to rebuild from scratch (see below).
 
 
 
'''''Rebuilding From Scratch'''''
 
To rebuild from scratch, you need to clean out any build files. First of all, if you want to keep the previously built version, rename the ''inkscape'' directory. Now open a command window and run the following;
    ...> mingwenv
    ...> btool clean
    ...> btool dist-all
 
==== Dealing With Build Errors ====
Feel free to add 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 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?
Line 209: Line 112:
Same error for line 2297 as well.
Same error for line 2297 as well.


==== For more information ====
=== 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
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


=== Create An Installation Package For Win32 ===
== Creating an installer ==


To create the setup package you need the NSIS installer on your PC. Get that from http://nsis.sf.net .
To create the setup package you need the NSIS installer on your PC. Get that from http://nsis.sf.net .
Line 218: Line 121:
Open the ...\Inkscape\packaging\win32\inkscape.nsi using the NSIS program and compile the package. Sooo easy :-)
Open the ...\Inkscape\packaging\win32\inkscape.nsi using the NSIS program and compile the package. Sooo easy :-)


== Note about Unicode ==


==== A Note from Jon about UNICODE on Win32 ====
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.
 
Actually, Microsoft themselves never use _UNICODE, nor it's 'evil' friends TCHAR and _T.
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.
 
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"].
 
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.
 
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:
* 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://www.icu-project.org/ International Components for Unicode (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.  
 
The result? A single binary that executes properly on both [[Win9X/ME]] and [[WinNT/2K/XP]], including full and proper font and filename support.
 
And, as I've mentioned before, I've actually achieved this for a few different shipping products and projects.
 
-- [[JonCruz|Jon C]]
 
=== SVN and Windows ===
 
If you want to access Inkscapes' subversion repository on SourceForge from Windows, I'd heartily recommend [[TortoiseSVN]].
It has the SSH stuff built into it so you don't have to mess about with putty, and
it integrates right into Explorer, so SVN becomes just an extension of the right-click file commands.
get it from http://tortoisesvn.net/
 
John

Revision as of 00:21, 1 February 2010

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.

Setting up the build environment

To develop Inkscape, you will need the following things:

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

Check out Inkscape Devlibs into C:\devlibs. 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. Currently you need to use the path mentioned above.

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

To update devlibs:

C:\devlibs> bzr update

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 checkout lp:inkscape trunk

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 Inkscape

Open the command prompt, navigate to the directory with Inkscape sources. First set up some environmental variables. You only need to do this once per console session.

C:\src\inkscape\trunk> mingwenv

Now compile the build tool. Try the second command if the first one fails.

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

Finally initiate the compilation. Get a coffee or take your dog out for a walk, because it will take a rather long time.

C:\src\inkscape\trunk> btool

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

Creating an installer

To create the 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\Inkscape\ directory. Open the ...\Inkscape\packaging\win32\inkscape.nsi using the NSIS program and compile the package. Sooo easy :-)

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.