Professional Documents
Culture Documents
This file describes how to build the Mingw-w64 GCC toolchain as a cross-compiler
on Cygwin, MinGW with MSys, and *nix shells.
Cygwin 1.5 and 1.7 currently in beta testing are both supported. This document
recommends and assumes Bash (for Cygwin, Unix), or MSys core sh default shells
are used.
== Targeted audience ==
This document is written to help those new to building the mingw-w64 cross
compilers on Windows using MSYS/MinGW and Cygwin. It can also be adapted
slightly for building the mingw-w64 cross compiler on Linux.
The mingw-w64 cross compilers consists in a few basic packages, among which
binutils, gcc, and windows headers, compiled in a special way. Once it is
operational, it forms the base to compile the packages of your project.
A collection of packages built on top of mingw-w64 can be found in fedora,
opensuse. Prebuilt version of mingw-w64 can also be found in the mingw-w64
website.
For a more advanced guide on building the mingw-w64 cross compiler including
the optional dependencies, please refer to the "mingw-w64-howto-build-adv.txt"
guide.
== Version changes ==
== Table of Contents ==
* Requirements
[RQRMTS]
* Optional
[OPTNLB]
* Download new packages
[DWNWPK]
* Build type options
[BTYOPT]
* Building binutils cross toolchain
[CRSBNT]
* Install the Mingw-w64 header set and create required symlinks
[HDRSYM]
* Building the GCC core cross-compiler
[BDGCOR]
* Building the crt
[BLDCRT]
* Finishing GCC
[FNSHGC]
* Path update and using your new cross-compiler
[PTHUPD]
You can search the keys (i.e. [BLDCRT]) to jump to that section.
== Requirements == [RQRMTS]
You will need a complete GCC toolchain for the host system (Cygwin, MinGW/MSys
or Linux), which usually includes all of the required components:
== Optional == [OPTNLB]
* CVS
* Subversion (SVN)
* wget
* tar & gzip/bzip2
To build with MSys (Minimal SYStem for Win32), to satisfy the requirements
download and install functional MinGW (GCC toolchain), MSYS (sh shell), bison,
and flex.
If your host OS is Vista, you must install SP1 or SP2! If you can't, you must
use an unoptimized collect2.exe as a workaround, but you are on your own.
Win32 installers to use with mingw msys available for download at MinGW's
sourceforge page: http://sourceforge.net/project/showfiles.php?group_id=23617
GMP & MPFR sources may be placed in the GCC source tree root in directories
with their names and they will be built automatically by GCC's configure (as
static libs). You might need to make install from inside the directories if
GCC doesn't do it for you.
* GCC version 4.5.1 release for stable, or latest GCC (4.6) snapshot
or svn co for experimental. GCC-4.3 support is no longer maintained.
Official releases of GCC and binutils may be downloaded from a GNU FTP mirror
from <http://www.gnu.org/prep/ftp.html>. GCC snapshots may be found at
<ftp://gcc.gnu.org/pub/gcc/snapshots/>. Binutils snapshots may be found at
<ftp://sourceware.org/pub/binutils/snapshots/>. Extract the tarballs (i.e.
tar -xf filename.tar.gz) to a temporary folders.
You can also download the latest working version using SVN & CVS. Both source
control systems are available to Cygwin via Setup, and available to MSys in the
MSys/MinGW Packages. To use them:
* For Mingw-w64:
svn co https://mingw-w64.svn.sourceforge.net/svnroot/mingw-w64 mingw-w64
When building binutils, GCC and Mingw-w64, you will be using standard autotools
configure scripts. It is not a good idea to build in the source directory, so
you will make a sibling directory next to the source tree, enter it, and invoke
configure with '../path/to/configure' (which is then followed by 'make' and
then 'make install'.) You will be providing options to the configure script,
in the syntax of ../path/to/configure --flag[=setting]. This will be further
detailed below.
You have two main choices to make building the cross-compiler toolchain:
It is recommanded to use the two first options, as the third one will require
more knowledge to use it properly. In the rest of this howto, examples will be
provided for the '64 bits only' option and for the 'multilib enabled' option.
For the '32 bits' option, please replace 'x86_64-w64-mingw32' by
'i686-w64-mingw32' wherever you see it.
Step 1) Create a build directory (e.g. 'build'), where binutils compiled object
files will be stored. Then enter into it.
For non-multilib:
../path/to/configure --target=x86_64-w64-mingw32 \
--disable-multilib
Step 5) You may optionally delete the "build" directory to save disk space.
== Install the Mingw-w64 header set and create required symlinks == [HDRSYM]
Note: On Windows systems or other systems that do not support UNIX type
softlinks, you may copy the entire directory to mirror it. It will
have the same effect as a symlink.
Note: The header-set and crt contains the standard-c and the windows platform
headers. Therefore it is not necessary to install an additional package.
Step 1) Enter into the GCC root folder and generate a folder within (e.g.
'build'), then enter it.
Step 3) Type 'make all-gcc'. This will build the GCC core.
Step 4) Type 'make install-gcc'. This will install the GCC core.
Step 5) You can leave the "build" directory alone for now, so you can
resume building the rest of GCC later after installing the CRT.
Now the core stuff of GCC is present and we can build the crt itself.
Step 1) Create a new "build" directory for the crt. Enter the "build" directory.
Without multilib:
../path/to/configure --host=x86_64-w64-mingw32
Step 5) Make sure you have the following directories in the directory you
have installed the mingw-w64 toolchain to:
<root>/x86_64-w64-mingw32
<root>/x86_64-w64-mingw32/include
<root>/x86_64-w64-mingw32/lib
<root>/x86_64-w64-mingw32/lib32
<root>/x86_64-w64-mingw32/lib64 [link to lib]
<root>/mingw [link to x86_64-w64-mingw32]
<root>/mingw/include
<root>/mingw/lib
<root>/mingw/lib32
<root>/mingw/lib64 [link to lib]
If you are using MSys/MinGW on Windows, remember to copy the "linked"
directories to simulate the use of a symbolic link.
Note: For non-multilib builds, you can omit the "lib32" and "lib64"
directories and only have "lib".
Note: Currently there are no dlls built. As long as we use static crt import
libraries we won't need a ctor/dtor dll (mingwm10.dll).
== Finishing GCC (the libraries built using GCC core and Mingw-w64) == [FNSHGC]
The binaries are all prefixed with the Mingw-w64 triplet x86_64-w64-mingw32-,
so there are no file name clashes.
* If you are using Cygwin or *nix, you will add the directory to your path
in .bashrc in your home directory (the file may be hidden).
* If you are using MSys, you will need to add the directory to your path in
/etc/profile.
Often you must --enable-shared if you want DLLs as opposed to static libs,
but it is not always the case.
Simply use the -mwindows option for windows GUI applications. By default,
-mconsole is used and produce console applications. Also, you can use the
-mdll option for generating shared objects (dll), however normal gcc/g++
with the -shared flag or a proper ld (linker) command will do this.