| How to build a Mingw-w64 x86_64-w64-mingw32 cross-compiler. |
| |
| (At this time, building a native compiler is suggested. Documentation |
| to follow. This is all still required to be able to build it.) |
| Top-level configure to do this all with one command is also to follow. |
| |
| As of 2009-05-31, x86_64-pc-mingw32 has been replaced by x86_64-w64-mingw32. |
| The change allows for mingw-w64 to have a host/target type independent of |
| mingw.org's MinGW. |
| |
| All default libraries work! We are now in a 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> |
| 2009-06-06 1.6 Xenofears <xenofears at gmail.com> |
| 2009-08-28 1.7 Xenofears <xenofears at gmail.com> |
| 2009-08-30 1.8 <sezeroz at gmail dot com> |
| |
| 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. |
| |
| == Requirements == |
| |
| You will need a complete GCC toolchain for the host system (Cygwin, MinGW/MSys |
| or Linux), which usually includes all of the required components: |
| |
| * GCC (for the native platform) |
| * Binutils (for the native platform) |
| * Bison |
| * Flex |
| * Coreutils |
| * 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) |
| |
| == Optional == |
| |
| Optional for source download / version management: |
| |
| * CVS |
| * Subversion (SVN) |
| * wget |
| * tar & gzip/bzip2 |
| |
| Optional for optimization enhancements: (Math toolchain dependencies are |
| elaborated on GMP) |
| |
| * PPL 0.10 or newer |
| * ClooG-PPL 0.15 or newer (must be ppl) |
| * MPC 0.6 or newer |
| |
| 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. |
| |
| |
| == Download new packages == |
| |
| You need to download the following packages: |
| |
| * Binutils 2.19.1 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.1 release for stable, or latest gcc (4.5) snapshot |
| or svn co for experimental as of 06-01-2009. Gcc-4.5 is good for |
| proper support for the new -w64-, see note above, but is in Stage 1 |
| yet and may have bugs. Gcc-4.3 support is no longer maintained. |
| |
| * Current Mingw-w64 release available at |
| http://sourceforge.net/projects/mingw-w64 . Snapshot, even better |
| from SVN (refer below), recommended until stable issuance), or you |
| can download the latest source release snapshot issued from Cadforte, |
| http://www.cadforte.com/downloads.html , which includes full tree |
| including experimental branch. |
| |
| 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 |
| |
| * For GCCs latest development snapshot (4.5.0): |
| svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc45x |
| or for GCC 4.4.x: |
| svn co svn://gcc.gnu.org/svn/gcc/branches/gcc-4_4-branch gcc44x |
| |
| * For Binutils: |
| cvs -z9 -d:pserver:anoncvs@sourceware.org:/cvs/src co binutils |
| (a directory named 'src' will be created and will hold the sources.) |
| |
| |
| === Build type options === |
| |
| 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 subdirectory in the tree, enter it, and invoke configure with |
| '../configure' (which is then followed by 'make' and then 'make install'.) You |
| will be providing options to the configure script, in the syntax of |
| ../configure --flag[=setting]. This will be further detailed below. |
| |
| You have two main choices to make building the cross-compiler toolchain: |
| |
| 1) To build with default standard multilib (allows for building to a 32-bit |
| alternate target, using Mingw-w64's lib32), or to disable multilib. Multilib |
| is installed by default, if you don't want it, you have to explicitly disable |
| it by passing --disable-multilib to configure, i.e. |
| ../configure --disable-multilib |
| |
| 2) Using standard settings of configure, which installs to /usr/local and |
| requires no setting changes, or to build to a sysroot you designate. /usr/local |
| is universally used as the default install point, and you may wish to keep all |
| the Mingw-w64 (64-bit) in a separate sysroot instead. In the example in these |
| instructions, the sysroot is '/mypath'. To use a sysroot, pass |
| --with-sysroot=/mypath and --prefix=/mypath as configure flags, i.e. |
| ../configure --with-sysroot=/mypath --prefix=/mypath |
| |
| |
| == Building binutils cross toolchain == |
| |
| Step 1) Enter into the binutils extracted source root folder and create a new |
| folder within (e.g. 'build'). Then enter into it. |
| |
| Step 2) Run configure. |
| For multilib: |
| ../configure --target=x86_64-w64-mingw32 \ |
| --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32 |
| |
| For no multilib: |
| ../configure --target=x86_64-w64-mingw32 \ |
| --disable-multilib |
| |
| If using a sysroot, add "--with-sysroot=/mypath --prefix=/mypath" to |
| your configure command, i.e., for multilib: |
| ../configure --target=x86_64-w64-mingw32 \ |
| --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32 \ |
| --with-sysroot=/mypath --prefix=/mypath |
| |
| Step 3) Run make (type 'make'). This will take a while. |
| |
| Step 4) Run make install (type 'make install') |
| |
| |
| == Install the Mingw-w64 header set and create required symlinks == |
| |
| Step 1) Enter into the Mingw-w64 source headers. It is in |
| mingw-w64/trunk/mingw-w64-headers, or mingw-w64/mingw-w64-headers |
| depending on your source. |
| |
| Step 2) Copy the 'include' directory here into your installation directory's |
| new x86_64-w64-mingw32 subdirectory. So, if using configure default |
| /usr/local, type 'cp -r include /usr/local/x86_64-w64-mingw32'. |
| If using a sysroot, type 'cp -r include /mypath/x86_64-w64-mingw32/' |
| |
| Step 3) GCC requires the x86_64-w64-mingw32 directory be mirrored as a |
| directory 'mingw' in the same root. So, if using configure default |
| /usr/local, type: |
| ln -s /usr/local/x86_64-w64-mingw32 /usr/local/mingw |
| or, for sysroot, type: |
| ln -s /mypath/x86_64-w64-mingw32 /mypath/mingw |
| |
| Step 4) Manually create the x86_64-w64-mingw32/lib directory: |
| mkdir /usr/local/x86_64-w64-mingw32/lib |
| or, for sysroot: |
| mkdir /mypath/x86_64-w64-mingw32/lib |
| If it already exists and you get an error, ignore it. |
| |
| Step 5) Symlink x86_64-w64-mingw32/lib directory as x86_64-w64-mingw32/lib64: |
| ln -s /usr/local/x86_64-w64-mingw32/lib /usr/local/x86_64-w64-mingw32/lib64 |
| or, for sysroot: |
| ln -s /mypath/x86_64-w64-mingw32/lib /mypath/x86_64-w64-mingw32/lib64 |
| |
| Note: If you are using MSys, you will need to do Step 5 again after building |
| the crt (it will be noted in the instructions.) 'ln -s' makes symlinks, which |
| are kind of like *nix shortcuts, as a major simplification, but MSys doesn't |
| support that and just copies the files instead of making a pointer object. |
| |
| 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. |
| |
| |
| == Building the gcc core cross-compiler(s) == |
| |
| There are no gcc patches required anymore. We keep up with gcc and get any |
| fixes applied upsteam. |
| |
| Step 1) Enter into the gcc root folder and generate a folder within (e.g. |
| 'build'), then enter it. |
| |
| Step 2) Run configure. |
| For multilib: |
| ../configure --target=x86_64-w64-mingw32 --enable-targets=all |
| To disable multilib: |
| ../configure --target=x86_64-w64-mingw32 --disable-multilib |
| |
| Add the --prefix=/mypath and --with-sysroot=/mypath flags if you are |
| using a sysroot. |
| |
| Step 3) Type 'make all-gcc'. This will build the gcc core. |
| |
| Step 4) Type 'make install-gcc'. This will install the gcc core. |
| |
| Now the core stuff of gcc is present and we can build the crt itself. |
| |
| |
| == Building the crt (Mingw-w64 itself) == |
| |
| Step 1) Put the gcc that you just installed into your PATH. |
| For configure default /usr/local : |
| PATH="/usr/local/bin:$PATH" |
| export PATH |
| For custom sysroot: |
| PATH="/mypath/bin:$PATH" |
| export PATH |
| |
| Step 2) Enter into the trunk/mingw-w64-crt source directory and generate a |
| directory within (e.g. build), and enter into it. |
| |
| Step 3) Run configure. |
| For multilib: |
| ../configure --host=x86_64-w64-mingw32 --enable-lib32 |
| (NOTE: This won't work if you disabled multilib!) |
| |
| Without multilib: |
| ../configure --host=x86_64-w64-mingw32 |
| |
| If using sysroot/prefix, again add the the --prefix=/mypath and |
| --with-sysroot=/mypath flags. |
| |
| Step 4) Type make. This will take a while. |
| |
| Step 5) Type make install |
| |
| Step 6) If you are using MSys/MinGW, repeat Step 5 of 'Install the Mingw-w64 |
| header set...' |
| |
| Note: Currently there is no dll build. As long as we use static crt import |
| libraries we won't need a ctor/dtor dll. |
| |
| |
| == Finishing gcc (the libraries built using gcc core and Mingw-w64) == |
| |
| Now you are ready to build the rest of gcc: |
| |
| Step 1) Enter back into your generated folder within your gcc root source |
| folder. |
| |
| Step 2) Type 'make'. This will take a while. |
| |
| Step 3) Type 'make install' |
| |
| |
| == Path update and using your new cross-compiler == |
| |
| Permanently update your path to use your new cross-compiler: |
| |
| 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. |
| |
| * To reiterate, for default /usr/local, Add /usr/local/bin to your path (this |
| should not be necessary.) If using a sysroot, add /mypath/bin to your path. |
| |
| 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 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. |
| |