Debian Codegraph @

mingw-w64-doc/howto-build/mingw-w64-howto-build.txt

raw
1 How to build a Mingw-w64 x86_64-w64-mingw32 cross-compiler.
2
3 == About this document ==
4
5 (At this time, building a native compiler is suggested. Documentation
6 to follow. This is all still required to be able to build it.)
7 Top-level configure to do this all with one command is also to follow.
8
9 As of 2009-05-31, x86_64-pc-mingw32 has been replaced by x86_64-w64-mingw32.
10 The change allows for mingw-w64 to have a host/target type independent of
11 mingw.org's MinGW.
12
13 All default libraries work! We are now in a functional beta stage.
14
15 This file describes how to build the Mingw-w64 GCC toolchain as a cross-compiler
16 on Cygwin, MinGW with MSys, and *nix shells.
17
18 Cygwin 1.5 and 1.7 currently in beta testing are both supported. This document
19 recommends and assumes Bash (for Cygwin, Unix), or MSys core sh default shells
20 are used.
21
22 == Targeted audience ==
23
24 This document is written to help those new to building the mingw-w64 cross
25 compilers on Windows using MSYS/MinGW and Cygwin. It can also be adapted
26 slightly for building the mingw-w64 cross compiler on Linux.
27
28 The mingw-w64 cross compilers consists in a few basic packages, among which
29 binutils, gcc, and windows headers, compiled in a special way. Once it is
30 operational, it forms the base to compile the packages of your project.
31 A collection of packages built on top of mingw-w64 can be found in fedora,
32 opensuse. Prebuilt version of mingw-w64 can also be found in the mingw-w64
33 website.
34
35 For a more advanced guide on building the mingw-w64 cross compiler including
36 the optional dependencies, please refer to the "mingw-w64-howto-build-adv.txt"
37 guide.
38
39 == Version changes ==
40
41 Date / Version / Author
42 2007-07-31 1.0 Kai Tietz <Kai.Tietz at onevision.com>
43 2007-08-20 1.1 Kai Tietz <Kai.Tietz at onevision.com>
44 2007-08-21 1.2 NightStrike <nightstrike at gmail.com>
45 2007-10-01 1.3 NightStrike <nightstrike at gmail.com>
46 2007-11-27 1.4 NightStrike <nightstrike at gmail.com>
47 2009-05-31 1.5 Xenofears <xenofears at gmail.com>
48 2009-06-06 1.6 Xenofears <xenofears at gmail.com>
49 2009-08-28 1.7 Xenofears <xenofears at gmail.com>
50 2009-08-30 1.8 Ozkan Sezer <sezeroz at gmail dot com>
51 2009-10-09 1.9 Jonathan Yong <jon_y[a]users.sourceforge.com>
52 2010-02-28 1.10 Ozkan Sezer <sezeroz at gmail dot com>
53 2010-08-31 1.11 Jonathan Yong <jon_y[a]users.sourceforge.com>
54 2012-03-06 1.12 William <r.3[a]libertysurf.fr>
55 2013-01-27 1.13 Jonathan Yong <jon_y[a]users.sourceforge.com>
56
57 == Table of Contents ==
58
59 * Requirements [RQRMTS]
60 * Optional [OPTNLB]
61 * Download new packages [DWNWPK]
62 * Build type options [BTYOPT]
63 * Building binutils cross toolchain [CRSBNT]
64 * Install the Mingw-w64 header set and create required symlinks [HDRSYM]
65 * Building the GCC core cross-compiler [BDGCOR]
66 * Building the crt [BLDCRT]
67 * Finishing GCC [FNSHGC]
68 * Path update and using your new cross-compiler [PTHUPD]
69
70 You can search the keys (i.e. [BLDCRT]) to jump to that section.
71
72 == Requirements == [RQRMTS]
73
74 You will need a complete GCC toolchain for the host system (Cygwin, MinGW/MSys
75 or Linux), which usually includes all of the required components:
76
77 * GCC (for the native platform)
78 * Binutils (for the native platform)
79 * Bison
80 * Flex
81 * gperf (Optional, for developing on GCC)
82 * Coreutils
83 * Make (3.81 or newer)
84 * GMP 4.3.1 or newer
85 [found on Cygwin setup under math]
86 * MPFR 2.4.1 or newer
87 [found on Cygwin setup under math]
88 * Perl (optional for pod2man)
89
90 == Optional == [OPTNLB]
91
92 Optional for source download / version management:
93
94 * CVS
95 * Subversion (SVN)
96 * wget
97 * tar & gzip/bzip2
98
99 Optional for optimization enhancements: (Math toolchain dependencies are
100 elaborated on GMP)
101
102 * PPL 0.10 or newer
103 * ClooG-PPL 0.15 or newer (must be ppl)
104 * MPC 0.7 or newer
105
106 To build with MSys (Minimal SYStem for Win32), to satisfy the requirements
107 download and install functional MinGW (GCC toolchain), MSYS (sh shell), bison,
108 and flex.
109
110 If your host OS is Vista, you must install SP1 or SP2! If you can't, you must
111 use an unoptimized collect2.exe as a workaround, but you are on your own.
112
113 Win32 installers to use with mingw msys available for download at MinGW's
114 sourceforge page: http://sourceforge.net/project/showfiles.php?group_id=23617
115
116 GMP & MPFR sources may be placed in the GCC source tree root in directories
117 with their names and they will be built automatically by GCC's configure (as
118 static libs). You might need to make install from inside the directories if
119 GCC doesn't do it for you.
120
121
122 == Download new packages == [DWNWPK]
123
124 You need to download the following packages:
125
126 * At least CVS snapshot (2.20.51). Note that 2.20.1 is not supported
127 due to ABI changes.
128
129 * GCC version 4.5.1 release for stable, or latest GCC (4.6) snapshot
130 or svn co for experimental. GCC-4.3 support is no longer maintained.
131
132 * Current Mingw-w64 release available at
133 http://sourceforge.net/projects/mingw-w64 . Snapshot, even better
134 from SVN (refer below), recommended until stable issuance.
135
136 Official releases of GCC and binutils may be downloaded from a GNU FTP mirror
137 from <http://www.gnu.org/prep/ftp.html>. GCC snapshots may be found at
138 <ftp://gcc.gnu.org/pub/gcc/snapshots/>. Binutils snapshots may be found at
139 <ftp://sourceware.org/pub/binutils/snapshots/>. Extract the tarballs (i.e.
140 tar -xf filename.tar.gz) to a temporary folders.
141
142 You can also download the latest working version using SVN & CVS. Both source
143 control systems are available to Cygwin via Setup, and available to MSys in the
144 MSys/MinGW Packages. To use them:
145
146 * For Mingw-w64:
147 svn co https://mingw-w64.svn.sourceforge.net/svnroot/mingw-w64 mingw-w64
148
149 * For GCCs latest development snapshot (4.5.0):
150 svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc45x
151 or for GCC 4.4.x:
152 svn co svn://gcc.gnu.org/svn/gcc/branches/gcc-4_4-branch gcc44x
153
154 * For Binutils latest development snapshot (2.20.51):
155 cvs -z9 -d:pserver:[email protected]:/cvs/src co binutils
156 or for binutils-2.20 stable branch:
157 cvs -z9 -d:pserver:[email protected]:/cvs/src co -r binutils-2_20-branch binutils
158 (a directory named 'src' will be created and will hold the sources
159 for either of the cases.)
160
161
162 === Build type options === [BTYOPT]
163
164 When building binutils, GCC and Mingw-w64, you will be using standard autotools
165 configure scripts. It is not a good idea to build in the source directory, so
166 you will make a sibling directory next to the source tree, enter it, and invoke
167 configure with '../path/to/configure' (which is then followed by 'make' and
168 then 'make install'.) You will be providing options to the configure script,
169 in the syntax of ../path/to/configure --flag[=setting]. This will be further
170 detailed below.
171
172 Note: Do not build GCC in the source tree or in a subdirectory contained in
173 source tree. This generally applies to many other autotools based
174 packages too, unless specifically specified by the package developers
175 or maintainers.
176
177 You have two main choices to make building the cross-compiler toolchain:
178
179 1) To build a cross-compiler that will generate 32 bits binaries, 64 bits
180 binaries, or that will be multilib enabled (so that the toolchain can target
181 both, using Mingw-w64's lib32).
182
183 * 32 bits only : use options such as '--host=i686-w64-mingw32',
184 '--target=i686-w64-mingw32' with '--disable-multilib'
185
186 * 64 bits only : use options such as '--host=x86_64-w64-mingw32',
187 '--target=x86_64-w64-mingw32' with '--disable-multilib'
188
189 * multilib enabled : use options such as '--host=x86_64-w64-mingw32',
190 '--target=x86_64-w64-mingw32','--enable-targets=all','--enable-lib32' or
191 '--enable-targets=x86_64-w64-mingw32,i686-w64-mingw32'
192
193 It is recommanded to use the two first options, as the third one will require
194 more knowledge to use it properly. In the rest of this howto, examples will be
195 provided for the '64 bits only' option and for the 'multilib enabled' option.
196 For the '32 bits' option, please replace 'x86_64-w64-mingw32' by
197 'i686-w64-mingw32' wherever you see it.
198
199 2) Using standard settings of configure, which installs to /usr/local and
200 requires no setting changes, or to build to a sysroot you designate. /usr/local
201 is universally used as the default install point, and you may wish to keep all
202 the Mingw-w64 (64-bit) in a separate sysroot instead. In the example in these
203 instructions, the sysroot is '/mypath'. To use a sysroot, pass
204 --with-sysroot=/mypath and --prefix=/mypath as configure flags, i.e.
205 ../path/to/configure --with-sysroot=/mypath --prefix=/mypath
206
207
208 == Building binutils cross toolchain == [CRSBNT]
209
210 Step 1) Create a build directory (e.g. 'build'), where binutils compiled object
211 files will be stored. Then enter into it.
212
213 Step 2) Run configure.
214 For multilib:
215 ../path/to/configure --target=x86_64-w64-mingw32 \
216 --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32
217
218 For non-multilib:
219 ../path/to/configure --target=x86_64-w64-mingw32 \
220 --disable-multilib
221
222 If using a sysroot, add "--with-sysroot=/mypath --prefix=/mypath" to
223 your configure command, i.e., for multilib:
224 ../path/to/configure --target=x86_64-w64-mingw32 \
225 --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32 \
226 --with-sysroot=/mypath --prefix=/mypath
227
228 Step 3) Run make (type 'make'). This will take a while.
229
230 Step 4) Run make install (type 'make install')
231
232 Step 5) You may optionally delete the "build" directory to save disk space.
233
234 Step 6) If you are using "--prefix" to install binutils to a directory not in
235 your $PATH environmental variable, you should add the "bin" directory
236 to you $PATH, i.e., for binutils installed to /home/luser/mingw64, use
237 the following command to make new cross binutils visible by issuing:
238 export PATH="$PATH:/home/luser/mingw64/bin"
239 This step is required for building GCC later.
240
241 == Install the Mingw-w64 header set and create required symlinks == [HDRSYM]
242
243 Step 1) The source directory for the headers can be
244 mingw-w64/trunk/mingw-w64-headers, or mingw-w64/mingw-w64-headers
245 depending on your source.
246
247 Step 2) Create another "build" directory, and enter it.
248 To install the headers, run:
249 ../path/to/configure --build=<your build machine> \
250 --host=x86_64-w64-mingw32 --prefix=/mypath
251 Then run "make install" to install the headers.
252
253 NOTE: For v3 (trunk as of writing, you MUST append x86_64-w64-mingw32 to your prefix, such as --prefix=/mypath/x86_64-w64-mingw32
254 NOTE: You MUST also do this for the CRT
255
256 Step 3) GCC requires the x86_64-w64-mingw32 directory be mirrored as a
257 directory 'mingw' in the same root. So, if using configure default
258 /usr/local, type:
259 ln -s /usr/local/x86_64-w64-mingw32 /usr/local/mingw
260 or, for sysroot, type:
261 ln -s /mypath/x86_64-w64-mingw32 /mypath/mingw
262
263 Step 4) Manually create the x86_64-w64-mingw32/lib directory:
264 mkdir -p /usr/local/x86_64-w64-mingw32/lib
265 or, for sysroot:
266 mkdir -p /mypath/x86_64-w64-mingw32/lib
267 If it already exists and you get an error, ignore it.
268
269 Step 5) Symlink x86_64-w64-mingw32/lib directory as x86_64-w64-mingw32/lib64:
270 ln -s /usr/local/x86_64-w64-mingw32/lib /usr/local/x86_64-w64-mingw32/lib64
271 or, for sysroot:
272 ln -s /mypath/x86_64-w64-mingw32/lib /mypath/x86_64-w64-mingw32/lib64
273
274 Note: On Windows systems or other systems that do not support UNIX type
275 softlinks, you may copy the entire directory to mirror it. It will
276 have the same effect as a symlink.
277
278 Note: The header-set and crt contains the standard-c and the windows platform
279 headers. Therefore it is not necessary to install an additional package.
280
281
282 == Building the GCC core cross-compiler(s) == [BDGCOR]
283
284 There are no GCC patches required anymore. We keep up with GCC and get any
285 fixes applied upstream.
286
287 Step 1) Enter into the GCC root folder and generate a folder within (e.g.
288 'build'), then enter it.
289
290 Step 2) Run configure.
291 For multilib:
292 ../path/to/configure --target=x86_64-w64-mingw32 --enable-targets=all
293 To disable multilib:
294 ../path/to/configure --target=x86_64-w64-mingw32 --disable-multilib
295
296 Note: Remember to add the --prefix=/mypath and --with-sysroot=/mypath flags
297 to match the binutils build if you are using a sysroot.
298
299 Step 3) Type 'make all-gcc'. This will build the GCC core.
300
301 Step 4) Type 'make install-gcc'. This will install the GCC core.
302
303 Step 5) You can leave the "build" directory alone for now, so you can
304 resume building the rest of GCC later after installing the CRT.
305
306 Now the core stuff of GCC is present and we can build the crt itself.
307
308
309 == Building the crt (Mingw-w64 itself) == [BLDCRT]
310
311 Step 1) Create a new "build" directory for the crt. Enter the "build" directory.
312
313 Step 2) Run configure.
314 For multilib:
315 ../path/to/configure --host=x86_64-w64-mingw32 --enable-lib32
316 (NOTE: This won't work if you disabled multilib!)
317
318 Without multilib:
319 ../path/to/configure --host=x86_64-w64-mingw32
320
321 If using sysroot/prefix, again add the the --prefix=/mypath and
322 --with-sysroot=/mypath flags.
323
324 NOTE: For v3 (trunk as of writing, you MUST append x86_64-w64-mingw32 to your prefix, such as --prefix=/mypath/x86_64-w64-mingw32
325 NOTE: You MUST also do this for the HEADERS
326
327 Step 3) Type make. This will take a while.
328
329 Step 4) Type make install
330
331 Step 5) Make sure you have the following directories in the directory you
332 have installed the mingw-w64 toolchain to:
333 <root>/x86_64-w64-mingw32
334 <root>/x86_64-w64-mingw32/include
335 <root>/x86_64-w64-mingw32/lib
336 <root>/x86_64-w64-mingw32/lib32
337 <root>/x86_64-w64-mingw32/lib64 [link to lib]
338 <root>/mingw [link to x86_64-w64-mingw32]
339 <root>/mingw/include
340 <root>/mingw/lib
341 <root>/mingw/lib32
342 <root>/mingw/lib64 [link to lib]
343 If you are using MSys/MinGW on Windows, remember to copy the "linked"
344 directories to simulate the use of a symbolic link.
345
346 Note: For non-multilib builds, you can omit the "lib32" and "lib64"
347 directories and only have "lib".
348
349 Note: Currently there are no dlls built. As long as we use static crt import
350 libraries we won't need a ctor/dtor dll (mingwm10.dll).
351
352
353 == Finishing GCC (the libraries built using GCC core and Mingw-w64) == [FNSHGC]
354
355 Now you are ready to build the rest of GCC:
356
357 Step 1) Enter back into your GCC "build" directory.
358
359 Step 2) Type 'make'. This will take a while.
360
361 Step 3) Type 'make install'
362
363
364 == Path update and using your new cross-compiler == [PTHUPD]
365
366 Permanently update your path to use your new cross-compiler:
367
368 The binaries are all prefixed with the Mingw-w64 triplet x86_64-w64-mingw32-,
369 so there are no file name clashes.
370
371 * If you are using Cygwin or *nix, you will add the directory to your path
372 in .bashrc in your home directory (the file may be hidden).
373
374 * If you are using MSys, you will need to add the directory to your path in
375 /etc/profile.
376
377 * To reiterate, for default /usr/local, add /usr/local/bin to your PATH (this
378 should not be necessary.) If using a sysroot, add /mypath/bin to your path.
379
380 You are finished.
381
382 To use your cross-compiler, simply use --host=x86_64-w64-mingw32 as a
383 configure option. Be sure to -I/usr/local/include or -I/mypath/include
384 and -L/usr/local/lib or -L/mypath/lib to your CFLAGS to link your builds.
385
386 Often you must --enable-shared if you want DLLs as opposed to static libs,
387 but it is not always the case.
388
389 Simply use the -mwindows option for windows GUI applications. By default,
390 -mconsole is used and produce console applications. Also, you can use the
391 -mdll option for generating shared objects (dll), however normal gcc/g++
392 with the -shared flag or a proper ld (linker) command will do this.
393