blob: c6fbd3f2b41dee93f0303fddd6cec027f60ecb94 [file] [log] [blame]
HowTo build x86_64-w64-mingw32 cross-compiler
NOTE: x86_64-pc-mingw32 is now replaced by x86_64-w64-mingw32. The change allows for Mingw64 to be independent of Mingw32.
This is new for GCC 4.5.
All default libraries work! We are now in a very functional beta stage.
Date / Version / Author
2007-07-31 1.0 Kai Tietz <Kai.Tietz at onevision.com>
2007-08-20 1.1 Kai Tietz <Kai.Tietz at onevision.com>
2007-08-21 1.2 NightStrike <nightstrike at gmail.com>
2007-10-01 1.3 NightStrike <nightstrike at gmail.com>
2007-11-27 1.4 NightStrike <nightstrike at gmail.com>
2009-05-31 1.5 Xenofears <xenofears at gmail.com>
This document describes how to build the amd64 Mingw32 gcc toolchain as a cross-compiler on Cygwin, MinGW MSys, and Unix 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.
0. Requirements
On a clean cygwin install, you will need the following additional packages installed:
A complete gcc toolchain for the host system
bison
diffutils
flex
make
gmp 4.2.4 or newer (4.3.1 recommended) [found on Cygwin setup under math]
mpfr 2.3.1 or newer (2.4.1 recommended) [found on Cygwin setup under math]
perl (optional for pod2man)
tar & gzip/bzip
optional for source download / version management:
cvs
subversion
wget
optional for optimization enhancements:
ppl 0.10 or newer
cloog-ppl 0.15 or newer (must be ppl)
mpc 0.6 or newer
If your host OS is Vista, you must install SP1 or SP2!
To build with MSys (Minimal SYStem for win32), download and install functional MinGW (gcc toolchain), MSys (sh shell), Bison, and Flex.
Win32 installers to use with mingw msys available for download at 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) with no further action required.
1. Download packages
You need to download the following packages:
- binutils 2.19 release for stable, or 2.19.51+ or newer or latest snapshot 2.19.51 for experimental as of 06-01-2009.
- gcc version 4.4 release for stable, or latest gcc 4.4 (4.4.1) or 4.5 snapshot for experimental as of 06-01-2009.
(gcc 4.5 recommended for proper support for the new -w64-, see note above.) gcc 4.3 support is no longer maintained.
- current mingw-w64 release or snapshot available at https://sourceforge.net/projects/mingw-w64 (snapshot recomended)
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
Now extract these tarballs to a temporary folder. E.g. use ~/w64src. For the tarballs with
extension .tar.gz or .tgz use the following command to extract : tar -xzf <tarball>'. For
tarballs with extension .tar.bz2 or .tbz2 use the command 'tar -xjf <tarball>'.
There are now three folders within you temporary folder: trunk, binutils, and gcc.
2. Build type options
You have at least two different choices to build the crosscompiler toolchain:
I) Using standard settings of configure.
II) Using --prefix and --with-sysroot configuration
I assume that '/usr/local/' is the <install-root> for build type I, the path specified using --with-sysroot is
the root for type II. For this example, it will be set to '/mypath'.
3. Building binutils cross toolchain:
Step 1) Enter into the binutils root folder and generate a folder within (e.g.
'build'). Then enter into it.
Step 2 for I) Type '../configure --target=x86_64-w64-mingw32'
Step 2 for II) Type '../configure --target=x86_64-w64-mingw32 --prefix=/mypath --with-sysroot=/mypath'.
Step 3) Type 'make'
Step 4) Type 'make install'
Create in /usr/local if Type I or /mypath if Type II a symbolic link named 'mingw' pointing to the directory 'x86_64-w64-mingw32'.
For instance:
$ cd /mypath [or cd /usr/local if Type I]
$ ln -s x86_64-w64-mingw32 mingw
For Type I this shouldn't be necessary, but it does come up on a few very rare exceptions.
Note:
The header-set and crt contains the standard-c and the windows (w32api) specific files. Therefore it is not necessary
to install an additional package. 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).
4. Building the gcc core cross-compiler(s):
Step 0) If you have to patch gcc, may do this here. There are some optional patches, available by the
'gcc-patches' mailing list at 'gcc.gnu.org' or by taking a look at mingw.org or mingw-w64 sites.
Step 1) Enter into the gcc root folder and generate a folder within (e.g. 'build'), then enter it.
Step 2 for I) Type: '../configure --target=x86_64-w64-mingw32'.
Step 2 for II) Type: '../configure --target=x86_64-w64-mingw32 --prefix=/mypath --with-sysroot=/mypath'.
Step 3) Type 'make all-gcc'
Step 4) Type 'make install-gcc'
Now the core stuff of gcc is present and we can build the crt itself.
5. Building the crt:
Step 0) Place the gcc that you just installed into your PATH.
Step 0 for I) Type PATH="$PATH:/usr/local/bin" ; export PATH
Step 0 for II) Type PATH="$PATH:/mypath/bin" ; export PATH
Step 1) Enter into the trunk/mingw-w64-crt root directory and generate a
directory within (e.g. 'build'), and enter into it.
Step 2 for I) Type '../configure --host=x86_64-w64-mingw32'
Step 2 for II) Type '../configure --host=x86_64-w64-mingw32 --prefix=/mypath --with-sysroot=/mypath'
Step 3) Type 'make'
Step 4) Type 'make install'
Note: Currently there is no dll build. As long as we use static crt libraries we won't need a ctor/dtor dll.
6. Now you are ready to build the rest of gcc:
Step 1) Enter into your generated folder within your gcc root source folder.
Step 2) Type 'make'
Step 3) Type 'make install'
7. Update your path and use your new cross-compiler:
Note: Do not add the directories below to the beginning of your path unless you want the cross-compiler to be used by default,
effectively making native Mingw/Cygwin/unix builds not possible.
Step 1) Update your path with the following:
(See Step 5 for syntax. Add to .bashrc in your /home/user account or to /etc/profile if MinGW MSys.)
for I) Add /usr/local/bin (if necessary), /usr/local/x86_64-pc-w64-mingw32/bin, and /usr/local/libexec/gcc/x86_64-w64-mingw32/4.X.X/
for II) Add /mypath/bin, /mypath/x86_64-w64-mingw32/bin, and /mypath/local/libexec/gcc/x86_64-w64-mingw32/4.X.X/
Where 4.X.X is the version of gcc you installed (go to the directory and check, latest 4.4 snapshots are 4.4.1 now)
The libexec path shouldn't be necessary, but it does come up on occasion.
You are finished. To use your cross-compiler, simply use --host=x86_64-w64-mingw32 as a configure option.
Be sure to -I/usr/local/include or -I/mypath/include and -L/usr/local/lib or -L/mypath/lib to your cflags to link your builds.
Often you must --enable-shared if you want DLL's as oppoosed to static libs, but it is not always possible, and the flag doesn't always work.