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

From Inkscape Wiki
Jump to navigation Jump to search
(→‎Building Your Own Binary: Updated to use TortoiseSVN)
m (→‎For more information: Upped heading level)
Line 148: Line 148:




==== 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



Revision as of 14:22, 22 March 2008

See the Win32 Build ticket for some info.

Inkscape under Windows

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 Inkscape download page


Building Your Own Binary

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;

  • You will need to download and install the MinGW compiler
  • You will also need the supporting libraries used by Inkscape
  • A recommended step is to download and install the TortoiseSVN program to help manage source files and patching
  • You need to download the source code and possibly apply patches if bug testing


Getting The Compiler & Libraries

Ishmal provides a complete set of compiler and library files on his website. You can get all packages from http://inkscape.modevia.com/win32libs/.

Before you download, check for the last versions. As of March 13 2008 those are:

The configuration files expect the packages in specific directories:

  • the compiler C:\MINGW (referenced by mingwenv.bat)
  • other libraries C:\DEVLIBS (referenced in build.xml used by buildtool)


Getting The Inkscape Source

The best way to get the source is straight from the SVN repository using the TortoiseSVN program. Follow these steps;

Setting up a local source repository:

  • Get TortoiseSVN from http://tortoisesvn.net/downloads
  • Install Tortoise SVN.
  • Once Tortoise is installed, make a working folder wherever you want.
  • 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:

  • Enter the folder you created for the source files. Right click and select SVN Checkout.
  • Enter the URL for the source code you want;
  • TortoiseSVN will now download the source files, which are just over 30Mb.

Notes:


Patching The Source Code

Using TortoiseSVN:

Tortoise makes patching quite easy. Follow these steps;

  • Download the patch to the src directory. It should be called {patchname}.patch or {patchname}.diff
  • Right click on the patch, and select TortoiseSVN -> Apply Patch...
  • You will now notice that the patched file has a red exclamation rather than a green tick. This signifies that it has been altered from the SVN version.
  • If you want to go back to the SVN version, simply right click on a file or inside a folder and select TortoiseSVN -> Revert. Doing this with a single file will only ask to revert that one file. Clicking on a folder folder will offer to revert all files in that folder.


Using the GNU patch program:

For those who love the command line, you can patch 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 indepently 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 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."


Building The Binary

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.


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

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.

If everything went well, you should now have you fresh Inkscape in the ...\Inkscape directory.

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? 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.

This could also be a relevant question if I want to try patching just one part of the code.

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


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.


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

Create the Setup package for Win32

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 :-)


A Note from Jon about UNICODE on Win32

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 "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

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.

-- 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