Professional Documents
Culture Documents
The commands are run under a MSYS/MinGW setup unless specified otherwise.
Using Cygwin or any other POSIX compatible shell should work.
== Targeted audience ==
This document assumes readers are familiar with the UNIX Command Line
and building the GNU toolchain in general, but would want a more fine
grained control over the capabilities of the cross compiler.
LTO for COFF targets can be enabled without installing libelf, as of gcc-4.6.0.
== Version changes ==
== Table of Contents ==
You can search the keys (i.e. [BMPCLIB]) to jump to that section.
== Some Basic Info about MinGW-w64 == [SBSCINF]
These libraries are used by GCC on the "host" side. It means that these
should be built for the system that will run the newly built GCC.
Homepage: <http://gmplib.org/>
Depends on: None
Depended by: MPC, MPFR, PPL, CLooG
GCC dependency type: Hard (GCC won't build without it)
GMP is primarily written in C and assembly, but it comes with C++ bindings.
The asm part is selected by the $host_cpu detected by configure. If your
platform is not detected properly, you can use --host=none-none-none to
disable asm optimizations. Be sure to set the correct CC, CXX, NM, RANLIB
and AR variables.
The C++ bindings are not built by default, but it is required by PPL. To fix
this, use "--enable-cxx" and "CPPFLAGS=-fexceptions". PPL needs the
-fexceptions part to throw exceptions properly, but it is not strictly
required.
On Windows hosts, only static or shared builds can be used at a time, but not
both. This is reasoned by the incompatible header set used by static/shared
builds. If you do use static builds, you should build any libs that depend on
it as static to prevent accidentally exporting GMP symbols in other dlls.
Homepage: <http://www.mpfr.org/>
Depends on: GMP
Depended by: None
GCC dependency type: Hard (GCC won't build without it)
Homepage: <http://www.multiprecision.org/>
Depends on: GMP
Depended by: None
GCC dependency type: Hard (GCC won't build without it)
Homepage: <http://www.cs.unipr.it/ppl/>
Depends on: GMP
Depended by: ClooG
GCC dependency type: None (GCC does not use it directly)
PPL requires that GMP be built with C++ bindings (--enable-cxx) and
-fexceptions (to allow exceptions to be thrown across GMP).
Homepage: <http://repo.or.cz/w/cloog-ppl.git>
Depends on: GMP, PPL
Depended by: None
GCC dependency type: Soft (GCC can build without it)
If you are planning to use CLooG with static PPL, remeber to add
'--with-host-libstdcxx="-lstdc++ -lsupc++"' to configure.
CLooG needs to be told to use the PPL backend, so use:
./configure --with-ppl=<PPL install prefix>
make
make install
Target support libraries are for use with mingw-w64 itself. It should not
be used by the host directly. Hence the target libs will need to be compiled
with a compiler targeting mingw-w64.
Download instructions:
cvs -d :pserver:anoncvs@sourceware.org:/cvs/pthreads-win32 login
{enter ``anoncvs'' for the password}
cvs -d :pserver:anoncvs@sourceware.org:/cvs/pthreads-win32 checkout pthreads
Patch: <http://sourceware.org/ml/pthreads-win32/2009/msg00030/w64sup.patch>
Note: pthreads-win32 does not come with a autotools based build system. It
uses a Makefile "GNUmakefile" to build the pthreads dll.
Note: To allow win64 support, apply the patch from the mailing list.
Its a lazy method because it involves building GCC with all enabled
front ends only once, without restarting the cross GCC build.
First of all, your host compiler (native system "gcc") must support ADA.
If your platform does not have GNAT binaries, use the binaries from:
<https://libre.adacore.com/libre/download/>
If you do not want ADA support, or confident about your host ADA support,
you can skip the ADA bootstrap phase.
To begin bootstrap ADA, you must grab the GCC source that will be used
for the mingw-w64 cross GCC, so that the ADA support is as close as
possible with the target GCC version.
Use the source to build a native compiler for your host machine. You must
enable at least C, ADA, and C++ support. It is advisable to prefix
(i.e. using --prefix=/opt/test) the entire native bootstrap toolchain
in order to avoid overwriting the compiler provided by your host system.
You should also build a prefixed native Binutils for use with the new
bootstrap compiler.
Remember to build GCC OUTSIDE its source directory, NOT inside it and
certainly NOT in a sub-directory.
When you checkout the svn trunk from the mingw-w64 developer repository, there
should be a directory called mingw-w64-headers. Install it with:
../path/to/mingw-w64-headers/configure --prefix=<prefix>/x86_64-w64-mingw32 \
--enable-sdk=none --build=<host triplet> --host=x86_64-w64-mingw32
make install
To view the available sdks, use --help. The prefix should be similar to the
prefix used for cross Binutils. Although the mingw-w64 cross GCC is not
installed yet, configure will not fail it as it only checks the --host option.
It is important to set the --host option correctly, failing to do so will
cause the cross GCC to fail to find the expected system headers.
Your install root for the mingw-w64 cross toolchain should contain the
following directories. Create the directories if missing. It is easier
to use "ln -s" softlinks to link directories than to copy them over.
<root>/x86_64-w64-mingw32
<root>/x86_64-w64-mingw32/include [headers previously installed here]
<root>/x86_64-w64-mingw32/lib
<root>/x86_64-w64-mingw32/lib32
<root>/x86_64-w64-mingw32/lib64 [link to neighbor lib]
<root>/mingw [link to x86_64-w64-mingw32]
<root>/mingw/include
<root>/mingw/lib
<root>/mingw/lib32
<root>/mingw/lib64 [link to neighbor lib]
GCC can be configured in many ways, the following is an example that worked.
Make sure to add your cross Binutils binaries to your $PATH before continuing.
If you did use the ADA compiler from adacore to produce a bootstrap ADA
compiler, make sure to add the prefix in such a way that it is found
before your default host compiler.
(i.e. export PATH=/opt/adaboot/bin:$PATH:/mingw64/path/bin)
Some of the configure options do not sound possible with a stage-1 cross,
but be assured that it has been tested.
Remember to build GCC OUTSIDE its source directory, NOT inside it and certainly
NOT in a sub-directory.
Example:
../gcc-trunk/configure --{host,build}=<build triplet> \
--target=x86_64-w64-mingw32 --enable-multilib --enable-64bit \
--{prefix,with-sysroot}=<prefix> --enable-version-specific-runtime-libs \
--enable-shared --with-dwarf --enable-fully-dynamic-string \
--enable-languages=c,ada,c++,fortran,objc,obj-c++ --enable-libgomp \
--enable-libssp --with-host-libstdcxx="-lstdc++ -lsupc++" \
--with-{gmp,mpfr,mpc,cloog,ppl}=<host dir> --enable-lto
Explanation:
--enable-version-specific-runtime-libs
Installs libgcc/libstdc++ and other target support libraries in such a
way that multiple GCC installs can coexist simultaneously.
--enable-shared
Builds shared support libraries
--with-dwarf
Use Dwarf debugging format by default
--enable-fully-dynamic-string
Enable dynamic std::string class to work around lazy initialization.
--enable-libgomp
Enable OpenMP support, it is not enabled by default on MinGW platforms.
Requires pthreads-win32 (target) installed.
--enable-libssp
Enable Stack Smash Protection, a buffer overrun detector.
--with-host-libstdcxx
Lists down the C++ support libraries to link with. This is useful
when using static PPL and CLooG.
--with-{gmp,mpfr,mpc,cloog,ppl}=<host dir>
Tells GCC where the host support libraries are installed to.
(i.e. search <host dir>/include & <host dir>/lib)
--enable-lto
Enables Link Time Optimization support.
Use "make all-gcc" to build the standalone GCC compiler without target
support libs. Install it with "make install-gcc".
When you checkout the svn trunk from the mingw-w64 developer repository, there
should be a directory called mingw-w64-crt.
Example configure:
../path/to/crt/configure --prefix=<prefix>/x86_64-w64-mingw32 --enable-
lib32 \
--enable-lib64 --build=<build triplet> --host=x86_64-w64-mingw32
Explanation:
--enable-lib32
If you enabled multilib support in x86_64-w64-mingw32-gcc, this will build
32bit libs for use with win32 programming. For $host_cpu i686-w64-mingw32,
it is enabled by default.
--enable-lib64
Enable building 64bit libs for use with win64 programming. For $host_cpu
x86_64-w64-mingw32, it is enabled by default.
Once the configure ends successfully, run "make && make install".
If you used symlinks or ntfs junction points to link the "lib*" directories,
you should be fine. If you manually copied x86_64-w64-mingw32 to mingw, you
must copy the "lib*" directories so that "lib64" mirrors "lib" and
"lib32" in "mingw" mirrors "x86_64-w64-mingw32/lib32"
Move it from:
<prefix>/lib/gcc/<arch>/lib32/libgcc_s.a to
<prefix>/lib/gcc/<arch>/<version>/32/libgcc_s.a
and
<prefix>/lib/gcc/<arch>/lib64/libgcc_s.a to
<prefix>/lib/gcc/<arch>/<version>/libgcc_s.a
The libgcc dll is also clobbered during install, search the build
directory for the dll and install it to separate directories as you
see fit. Make sure 32bit apps only see the 32bit variant, same for
64bit apps.
pthread-win32 is required for libgomp to work. Now that the CRT and
libgcc is installed, we can proceed with building the pthread dll.