• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1How 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
6to follow.  This is all still required to be able to build it.)
7Top-level configure to do this all with one command is also to follow.
8
9As of 2009-05-31, x86_64-pc-mingw32 has been replaced by x86_64-w64-mingw32.
10The change allows for mingw-w64 to have a host/target type independent of
11mingw.org's MinGW.
12
13All default libraries work!  We are now in a functional beta stage.
14
15This file describes how to build the Mingw-w64 GCC toolchain as a cross-compiler
16on Cygwin, MinGW with MSys, and *nix shells.
17
18Cygwin 1.5 and 1.7 currently in beta testing are both supported. This document
19recommends and assumes Bash (for Cygwin, Unix), or MSys core sh default shells
20are used.
21
22== Targeted audience ==
23
24This document is written to help those new to building the mingw-w64 cross
25compilers on Windows using MSYS/MinGW and Cygwin. It can also be adapted
26slightly for building the mingw-w64 cross compiler on Linux.
27
28The mingw-w64 cross compilers consists in a few basic packages, among which
29binutils, gcc, and windows headers, compiled in a special way. Once it is
30operational, it forms the base to compile the packages of your project.
31A collection of packages built on top of mingw-w64 can be found in fedora,
32opensuse. Prebuilt version of mingw-w64 can also be found in the mingw-w64
33website.
34
35For a more advanced guide on building the mingw-w64 cross compiler including
36the optional dependencies, please refer to the "mingw-w64-howto-build-adv.txt"
37guide.
38
39== Version changes ==
40
41Date /          Version /  Author
422007-07-31      1.0        Kai Tietz <Kai.Tietz at onevision.com>
432007-08-20      1.1        Kai Tietz <Kai.Tietz at onevision.com>
442007-08-21      1.2        NightStrike <nightstrike at gmail.com>
452007-10-01      1.3        NightStrike <nightstrike at gmail.com>
462007-11-27      1.4        NightStrike <nightstrike at gmail.com>
472009-05-31      1.5        Xenofears <xenofears at gmail.com>
482009-06-06      1.6        Xenofears <xenofears at gmail.com>
492009-08-28      1.7        Xenofears <xenofears at gmail.com>
502009-08-30      1.8        Ozkan Sezer <sezeroz at gmail dot com>
512009-10-09      1.9        Jonathan Yong <jon_y[a]users.sourceforge.com>
522010-02-28      1.10       Ozkan Sezer <sezeroz at gmail dot com>
532010-08-31      1.11       Jonathan Yong <jon_y[a]users.sourceforge.com>
542012-03-06      1.12       William <r.3[a]libertysurf.fr>
552013-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
70You can search the keys (i.e. [BLDCRT]) to jump to that section.
71
72== Requirements == [RQRMTS]
73
74You will need a complete GCC toolchain for the host system (Cygwin, MinGW/MSys
75or 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
92Optional for source download / version management:
93
94	* CVS
95	* Subversion (SVN)
96	* wget
97	* tar & gzip/bzip2
98
99Optional for optimization enhancements: (Math toolchain dependencies are
100elaborated 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
106To build with MSys (Minimal SYStem for Win32), to satisfy the requirements
107download and install functional MinGW (GCC toolchain), MSYS (sh shell), bison,
108and flex.
109
110If your host OS is Vista, you must install SP1 or SP2!  If you can't, you must
111use an unoptimized collect2.exe as a workaround, but you are on your own.
112
113Win32 installers to use with mingw msys available for download at MinGW's
114sourceforge page: http://sourceforge.net/project/showfiles.php?group_id=23617
115
116GMP & MPFR sources may be placed in the GCC source tree root in directories
117with their names and they will be built automatically by GCC's configure (as
118static libs).  You might need to make install from inside the directories if
119GCC doesn't do it for you.
120
121
122== Download new packages == [DWNWPK]
123
124You 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
136Official releases of GCC and binutils may be downloaded from a GNU FTP mirror
137from <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.
140tar -xf filename.tar.gz) to a temporary folders.
141
142You can also download the latest working version using SVN & CVS.  Both source
143control systems are available to Cygwin via Setup, and available to MSys in the
144MSys/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:anoncvs@sourceware.org:/cvs/src co binutils
156	  or for binutils-2.20 stable branch:
157	cvs -z9 -d:pserver:anoncvs@sourceware.org:/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
164When building binutils, GCC and Mingw-w64, you will be using standard autotools
165configure scripts.  It is not a good idea to build in the source directory, so
166you will make a sibling directory next to the source tree, enter it, and invoke
167configure with '../path/to/configure' (which is then followed by 'make' and
168then 'make install'.) You will be providing options to the configure script,
169in the syntax of ../path/to/configure --flag[=setting].  This will be further
170detailed below.
171
172Note: 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
177You have two main choices to make building the cross-compiler toolchain:
178
1791) To build a cross-compiler that will generate 32 bits binaries, 64 bits
180binaries, or that will be multilib enabled (so that the toolchain can target
181both, 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
193It is recommanded to use the two first options, as the third one will require
194more knowledge to use it properly. In the rest of this howto, examples will be
195provided for the '64 bits only' option and for the 'multilib enabled' option.
196For the '32 bits' option, please replace 'x86_64-w64-mingw32' by
197'i686-w64-mingw32' wherever you see it.
198
1992) Using standard settings of configure, which installs to /usr/local and
200requires no setting changes, or to build to a sysroot you designate. /usr/local
201is universally used as the default install point, and you may wish to keep all
202the Mingw-w64 (64-bit) in a separate sysroot instead.  In the example in these
203instructions, 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
210Step 1) Create a build directory (e.g. 'build'), where binutils compiled object
211	files will be stored. Then enter into it.
212
213Step 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
228Step 3) Run make (type 'make').  This will take a while.
229
230Step 4) Run make install (type 'make install')
231
232Step 5) You may optionally delete the "build" directory to save disk space.
233
234Step 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
243Step 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
247Step 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
253NOTE: For v3 (trunk as of writing, you MUST append x86_64-w64-mingw32 to your prefix, such as --prefix=/mypath/x86_64-w64-mingw32
254NOTE: You MUST also do this for the CRT
255
256Step 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
263Step 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
269Step 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
274Note: On Windows systems or other systems that do not support UNIX type
275softlinks, you may copy the entire directory to mirror it. It will
276have the same effect as a symlink.
277
278Note: The header-set and crt contains the standard-c and the windows platform
279headers. Therefore it is not necessary to install an additional package.
280
281
282== Building the GCC core cross-compiler(s) == [BDGCOR]
283
284There are no GCC patches required anymore.  We keep up with GCC and get any
285fixes applied upstream.
286
287Step 1) Enter into the GCC root folder and generate a folder within (e.g.
288	'build'), then enter it.
289
290Step 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
299Step 3) Type 'make all-gcc'.  This will build the GCC core.
300
301Step 4) Type 'make install-gcc'.  This will install the GCC core.
302
303Step 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
306Now 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
311Step 1) Create a new "build" directory for the crt. Enter the "build" directory.
312
313Step 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
324NOTE: For v3 (trunk as of writing, you MUST append x86_64-w64-mingw32 to your prefix, such as --prefix=/mypath/x86_64-w64-mingw32
325NOTE: You MUST also do this for the HEADERS
326
327Step 3) Type make.  This will take a while.
328
329Step 4) Type make install
330
331Step 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
346Note: For non-multilib builds, you can omit the "lib32" and "lib64"
347	directories and only have "lib".
348
349Note: 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
355Now you are ready to build the rest of GCC:
356
357Step 1) Enter back into your GCC "build" directory.
358
359Step 2) Type 'make'. This will take a while.
360
361Step 3) Type 'make install'
362
363
364== Path update and using your new cross-compiler == [PTHUPD]
365
366Permanently update your path to use your new cross-compiler:
367
368The binaries are all prefixed with the Mingw-w64 triplet x86_64-w64-mingw32-,
369so 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
380You are finished.
381
382To use your cross-compiler, simply use --host=x86_64-w64-mingw32 as a
383configure option.  Be sure to -I/usr/local/include or -I/mypath/include
384and -L/usr/local/lib or -L/mypath/lib to your CFLAGS to link your builds.
385
386Often you must --enable-shared if you want DLLs as opposed to static libs,
387but it is not always the case.
388
389Simply 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++
392with the -shared flag or a proper ld (linker) command will do this.
393
394