7 This document explains how to build XZ Utils for Microsoft Windows
8 using MinGW (Minimalist GNU for Windows).
10 This is currently experimental and has got very little testing.
11 No ABI stability is promised for liblzma.dll.
16 XZ Utils code is C99. It should be possible to compile at least
17 liblzma using any C99 compiler. Compiling the command line tools may
18 need a little extra work to get them built on new systems, because
19 they use some features that aren't standardized in POSIX.
21 MinGW is free software. MinGW runtime provides some functions that
22 made porting the command line tools easier. Most(?) of the MinGW
23 runtime, which gets linked into the resulting binaries, is in the
26 While most C compilers nowadays support C99 well enough (including
27 most compilers for Windows), MSVC doesn't. It seems that Microsoft
28 has no plans to ever support C99. Thus, it is not possible to build
29 XZ Utils using MSVC without doing a lot of work to convert the code.
30 Using prebuilt liblzma from MSVC is possible though, since the
31 liblzma API headers are in C89 and contain some non-standard extra
32 hacks required by MSVC.
35 Getting and Installing MinGW
37 You can download MinGW for 32-bit Windows from Sourceforge:
39 http://sourceforge.net/project/showfiles.php?group_id=2435
41 It is enough to pick Automated MinGW Installer and MSYS Base System.
42 Using the automated installer, select at least runtime, w32api,
43 core compiler, and MinGW make. From MSYS you actually need only
44 certain tools, but it is easiest to just install the whole MSYS.
46 To build for x86-64 version of Windows, you can download a snapshot
47 of MinGW targeting for 64-bit Windows:
49 http://sourceforge.net/project/showfiles.php?group_id=202880
51 You can use the 32-bit MSYS also for 64-bit build, since we don't
52 link against anything in MSYS, just use the tools from it. You may
53 use the make tool from 32-bit MinGW (mingw32-make.exe) although
54 probably the make.exe from MSYS works too.
56 Naturally you can pick the components manually, for example to try
57 the latest available GCC. It is also possible to use a cross-compiler
58 to build Windows binaries for example on GNU/Linux, or use Wine to
59 run the Windows binaries. However, these instructions focus on
63 Building for 32-bit Windows
65 Add MinGW and MSYS to PATH (adjust if you installed to non-default
68 C:\>set PATH=C:\MinGW\bin;C:\MSYS\1.0\bin;%PATH%
70 Then it should be enough to just run mingw32-make in this directory:
72 C:\xz-5.x.x\windows>mingw32-make
75 Building for 64-bit Windows
77 For 64-bit build the PATH has to point to 64-bit MinGW:
79 C:\>set PATH=C:\MinGW64\bin;C:\MSYS\1.0\bin;%PATH%
81 You need to pass W64=1 to mingw32-make (or make if you don't have
84 C:\xz-5.x.x\windows>mingw32-make W64=1
87 Additional Make Flags and Targets
89 You may want to try some additional optimizations, which may or
90 may not make the code faster (and may or may not hit possible
91 compiler bugs more easily):
93 mingw32-make CFLAGS="-O3 -fomit-frame-pointer -funroll-loops"
95 If you want to enable assertions (the assert() macro), use DEBUG=1.
96 You may want to disable optimizations too if you plan to actually
97 debug the code. Never use DEBUG=1 for production builds!
99 mingw32-make DEBUG=1 CFLAGS="-g -O0"
101 By default, liblzma is built as a DLL and the command line tools
102 linked dynamically against that liblzma.dll. To build static
103 versions instead, use STATIC=1:
105 mingw32-make STATIC=1
107 TODO: Static build is not implemented yet.
109 To copy the built binaries and required headers into a clean
110 directory, use the pkg target:
114 It first removes a possibly existing pkg directory, and then
115 recreates it with the required files.
117 TODO: The pkg target doesn't copy any license or other copyright
118 related information into the pkg directory.
121 Creating an Import Library for MSVC
123 The included Makefile creates import library liblzma.a which works
124 only(?) with MinGW. To use liblzma.dll for MSVC, you need to create
125 liblzma.lib using the lib command from MSVC:
127 lib /def:liblzma.def /out:liblzma.lib /machine:ix86
129 On x86-64, the /machine argument has to naturally be changed:
131 lib /def:liblzma.def /out:liblzma.lib /machine:x64
136 - Test Win64 support and add instructions about getting x86-64
139 - Static liblzma and statically linked command line tools
141 - Creating the import library for other compilers/linkers
143 - Building with other compilers for Windows
145 - liblzma currently uses cdecl. Would stdcall be more compatible?
147 - Support building more size-optimized liblzma (the HAVE_SMALL
148 define and other things that are needed)
150 - Support selecting which parts of liblzma to build to make the
151 library even smaller.
153 - Use the configure script on Windows just like it is used on all
159 Report bugs to <lasse.collin@tukaani.org> (in English or Finnish).
161 Take into account that I don't have MSVC and I cannot very easily
162 test anything on Windows. As of writing, I have tried MinGW and the
163 resulting binaries only under 32-bit Wine.