| HowTo build x86_64-pc-mingw32 cross-compiler |
| |
| 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> |
| |
| This document describes how to build the amd64 mingw32 gcc toolchain as a cross-compiler on cygwin and unix shells. |
| |
| 0. Requirements |
| |
| On a clean cygwin install, you will need the following additional packages installed: |
| A complete gcc toolchain for the host system |
| bison |
| cvs |
| diffutils |
| flex |
| gmp |
| make |
| mpfr |
| perl (for pod2man) |
| subversion |
| wget |
| |
| |
| |
| 1. Download packages |
| The following packages you need to download |
| - binutils 2.17.50 snapshot released after or equal to the 1st of July 2007. |
| - gcc version 4.3 snapshort released after or equal to the 1st of July 2007. |
| - current mingw-w64-snapshot available at https://sourceforge.net/projects/mingw-w64 |
| |
| 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-pc-mingw32' |
| Step 2 for II) Type '../configure --target=x86_64-pc-mingw32 --prefix=/mypath --with-sysroot=/mypath'. |
| Step 3) Type 'make' |
| Step 4) Type 'make install' |
| |
| Now copy the content of the folder 'trunk/mingw-w64-headers/include' into your '<install-root>/x86_64-pc-mingw32/include' |
| folder. If you choose the configuration variant II create in /mypath a symbolic link named |
| 'mingw' pointing to the directory 'x86_64-pc-mingw32'. For instance: |
| $ cd /mypath |
| $ ln -s x86_64-pc-mingw32 mingw |
| |
| 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 patches necessary, if you want |
| to cross compile libiberty with early header sets, or if you want to use gfortran. These patches |
| are 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 you may |
| apply optional patches to gcc (currently there is a patch file for gcc needed to fix some |
| problems about autoimported variables, libiberty and the fortan compiler). Enter into the |
| build directory when finished. |
| Step 2 for I) Type: '../configure --target=x86_64-pc-mingw32'. |
| Step 2 for II) Type: '../configure --target=x86_64-pc-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) If you are using variant II, may you need to adjust the 'prefix' value in Makefiles. |
| Step 1) Enter into the trunk/mingw-w64-crt root directory. |
| Step 2 for I) Type 'make' |
| Step 2 for II) Type 'make prefix=/mypath' |
| (Note: If building the cross compiler on a system where the default executable extension is not .exe, override |
| the EXEEXT variable on the make commandline by adding "EXEEXT=".) |
| Step 3) Copy all generated *.a files out of the 'mklibs' folder into the |
| '<install-root>/x86_64-pc-mingw32/lib' folder. |
| Step 4) Copy out of the root folder to the '<install-root>/x86_64-pc-mingw32/lib' folder the files |
| crt1.o, crt2.o, lib*.a, *.dll, crtbegin.o, crtend.o, dllcrt1.o, dllcrt2.o, binmode.o, txtmode.o, |
| CRT_fp8.o, and the CRT_fp10.o |
| 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' |
| |