Revision of RelocatableHOWTOforMinGW from 2009, May 17 - 23:54

Printer-friendly version

HOWTO Understanding effects of build directory options on a relocatable MinGW GCC default's paths

1 Summury and purpose of this document

There are some things which are still marked as TODO is in this. This gonna be done later.

Target of this document: trying to better understand the effect of build time options on the resulting MinGW GCC's default paths. This is done testing the effect of some configuration options. These tests target the wish to have a multi-arch singled-versioned and relocatable installation directory. Comments and analysies given in this document, all goes to this direction. This document may not fullfill expectations from peoples with other wishes.

Test builds are done on Windows (XP or whatever below and above will probably give the same result) using MinGW as the C compiler and mSys as the build environnement (this is mandatory to run configuration and make scripts).

The document is divided into two main parts: tests at build time and tests with a relocated installation directory (the bigest part).

2 Tests at build time

2.1 The build was done with the following options:

2.1.1 Script variables:

  • mypkgname=....
  • name=gcc
  • package=gcc-4.2.1-2
  • build=i386-mingw32
  • host=i386-mingw32
  • target=i386-mingw32
  • prefix=/<my-msys-personal-home-dir>/$name
  • temp=$name

2.1.2 Options:

  • --with-pkgversion=$mypkgname
  • --build=$build
  • --host=$host
  • --target=$target
  • --prefix=$prefix
  • --with-sysroot=$prefix/$target/test1
  • --with-local-prefix=$prefix/$target/test2
  • --with-build-sysroot=$prefix/$target/test3
  • --disable-rpath
  • --disable-version-specific-runtime-libs
  • --enable-languages=c
  • --enable-libada
  • --enable-threads
  • --disable-shared
  • --disable-sjlj-exceptions
  • --disable-win32-registry
  • --enable-nls
  • --disable-bootstrap
  • --with-gnu-gcc
  • --with-gnu-as
  • --with-gnu-ld
  • --with-stabs


Do not forget:

  • Sysroot is set to /<install-dir>/<arch>/test1
  • Local prefix is set to /<install-dir>/<arch>/test2
  • Build sysroot is set to /<install-dir>/<arch>/test3
  • Prefix will be refered as /<install-dir>

A native compiler will be built the same way as if it was a cross compiler, to have a cleaner installation (each archs beside of each others, even the native one).

You will see these test1, test2, test3 in some paths list later. Do not forget what it is standing for (see above).

The build was started frm a build directory beside the source directory, with an installation directory bside the two laters, the a make and a make install was runned. The installation directory initially only contains <arch> and <arch>/test1 and <arch>/test2 and <arch>/test3.

Some thing was then deduced from error messages during the build process.

The build process expect a mingw/include in <install-dir>/<arch>/test3 (the build sysroot directory). It has complained with this message :

> The directory that should contain system headers does not exist:
> /<install-dir>/<arch>/test3/mingw/include

This mingw/include directory is mandatory during the build process, but it may be empty (the build process can terminates normally with an empty mingw/include).

The build process obviously complains about missing includes. Some test were done to list all directory where theses includes may be found.

2.3 Includes search when configuring gcc during the build process:

  • Not searched in /<install-dir>/include
  • Searched in /<install-dir>/<arch>/include
  • Not searched in /<install-dir>/<arch>/test1/include (sysroot/include)
  • Not searched in /<install-dir>/<arch>/test1/mingw/include (sysroot/mingw/include)
  • Not searched in /<install-dir>/<arch>/test2/include (localprefix/include)
  • Not searched in /<install-dir>/<arch>/test2/mingw/include (localprefix/mingw/include)
  • Not searched in /<install-dir>/<arch>/test3/include (buildsysroot/include)
  • Searched in /<install-dir>/<arch>/test3/mingw/include (buildsysroot/mingw/include)

2.4 Comments the latter

The <install-dir> did not contained any libs. The build still terminates normally.

Includes needed for the build process, are searched only in <arch>/include and in <build-sysroot>/mingw/include. It is worth to notice that <sysroot>/mingw/include is not searched nor is <sysroot>/include.

3 Tests on a relocated installation directory (get and drop anywhere)

Next, <install-dir> is renamed into an <reloc-dir>, to test how install relocation works.

3.1 The resulting gcc, after relocation, use the following default paths:

  • Install:
    • <install-dir>/lib/gcc/<arch>/<version>/
  • Programs:
    • <reloc-dir>/libexec/gcc/<arch>/<version>/
    • <reloc-dir>/libexec/gcc/
    • <install-dir>/libexec/gcc/<arch>/<version>/
    • <install-dir>/libexec/gcc/<arch>/<version>/
    • <install-dir>/libexec/gcc/<arch>/
    • <install-dir>/lib/gcc/<arch>/<version>/
    • <install-dir>/lib/gcc/<arch>/
    • /usr/libexec/gcc/<arch>/<version>/
    • /usr/libexec/gcc/<arch>/
    • /usr/lib/gcc/<arch>/<version>/
    • /usr/lib/gcc/<arch>/
    • <reloc-dir>/<arch>/bin/<arch>/<version>/
    • <reloc-dir>/<arch>/bin/
    • <install-dir>/<arch>/bin/<arch>/<version>/
    • <install-dir>/<arch>/bin/
  • Libraries:
    • <reloc-dir>/lib/gcc/<arch>/<version>/
    • <reloc-dir>/lib/gcc/
    • <install-dir>/lib/gcc/<arch>/<version>/
    • /usr/lib/gcc/<arch>/<version>/
    • <reloc-dir>/<arch>/lib/<arch>/<version>/
    • <reloc-dir>/<arch>/lib/
    • <install-dir>/<arch>/lib/<arch>/<version>/
    • <install-dir>/<arch>/lib/
    • <reloc-dir>/lib/<arch>/<version>/
    • <reloc-dir>/lib/
    • <install-dir>/lib/<arch>/<version>/
    • <install-dir>/lib/
    • <reloc-dir>/<arch>/test1/mingw/lib/<arch>/<version>/
    • <reloc-dir>/<arch>/test1/mingw/lib/
  • Includes:
    • <reloc-dir>/<arch>/test1<install-dir>/include
    • <install-dir>/lib/gcc/<arch>/<version>/include
    • <install-dir>/<arch>/include
    • <reloc-dir>/<arch>/test1/mingw/include
    • <reloc-dir>/lib/gcc/<arch>/<version>/include

3.2 Comments on the latter

Note: this list was obtained with “./gcc --print-search-dirs” and “./gcc -v -c test.c”, after reformating and canonicalization of paths, followed by some symbolic substitutions.

Note: cc1 received the following parameters for -prefix and -sysroot:

  • -iprefix <reloc-dir>/lib/gcc/<arch>/<version>/
  • -isysroot <reloc-dir>/<arch>/test1 (sysroot)

Suspected bug: Did you notice the first include path ? It seems there is a bug here. Two absolute paths are appended. I've meet it every time during all the teste I've made. I've also found some buggy paths concatenation in some Configure.log files. I dunno if it is a MinGW GCC bug or a configuration script bug or an mSys bug.

Note: some paths were printed with “/” as the path separator while some other was printed with “\” as the path separator. I've substitued all with “/” as MinGW GCC accept both.

Notice that <arch>/include only exist with the <install-dir> prefix. This may be a trouble (we will see later for the reason why).

Notice that the directory test3, which stands for --build-sysroot does not exist any more in the default search paths. It is only used at build time.

3.3 In the purpose of a relocatable installation, the list may be reduced to:

  • Programs:
    • <reloc-dir>/libexec/gcc/<arch>/<version>/
    • <reloc-dir>/libexec/gcc/
    • <reloc-dir>/<arch>/bin/<arch>/<version>/
    • <reloc-dir>/<arch>/bin/
  • Libraries:
    • <reloc-dir>/lib/gcc/<arch>/<version>/
    • <reloc-dir>/lib/gcc/
    • <reloc-dir>/<arch>/lib/<arch>/<version>/
    • <reloc-dir>/<arch>/lib/
    • <reloc-dir>/lib/<arch>/<version>/
    • <reloc-dir>/lib/
    • <reloc-dir>/<arch>/test1/mingw/lib/<arch>/<version>/
    • <reloc-dir>/<arch>/test1/mingw/lib/
  • Includes:
    • <reloc-dir>/<arch>/test1/mingw/include
    • <reloc-dir>/lib/gcc/<arch>/<version>/include

3.4 Comments on the latter

Note: this list is obtained removing all paths starting with <install-dir> and paths which are POSIX paths (ex. “/usr/libexec”), thus keeping only paths starting with <reloc-dir>. The first include buggy path was removed too (unusable anyway).

For options recieved by cc1:

  • -iprefix <reloc-dir>/lib/gcc/<arch>/<version>/
  • -isysroot <reloc-dir>/<arch>/test1 (sysroot)

It seems the directory mingw in expected in test1 (unlike at build time, where it was expected in test3).
Remind that test1 stands for sysroot.

3.5 In the purpose to have a clean single versioned relocatable installation, the list may be reduced again to:

  • Programs:
    • <reloc-dir>/libexec/gcc/
    • <reloc-dir>/<arch>/bin/
  • Libraries:
    • <reloc-dir>/lib/gcc/
    • <reloc-dir>/<arch>/lib/
    • <reloc-dir>/lib/
    • <reloc-dir>/<arch>/test1/mingw/lib/
  • Includes:
    • <reloc-dir>/<arch>/test1/mingw/include

3.6 Comments on the latter

Note: this list was obtained removing all paths containing <version>.

In the purpose of a multi-arch single versioned and relocatable installation, we notice there gonna be a trouble with the default include paths : it only looks in <reloc-dir>/<arch>/test1/mingw/include.

For options recieved by cc1: -isysroot <reloc-dir>/<arch>/test1 (sysroot)

-prefix, which was <reloc-dir>/lib/gcc/<arch>/<version>/ (see §3.3 and §3.4), use a versioned directory only.

The favorite path for programs would probably be <reloc-dir>/<arch>/bin/, the favorite paths for libs would probably be <reloc-dir>/lib/ and <reloc-dir>/<arch>/lib/. There are no good candidates for includes (an <arch>/include would be nice).

A special specs file may be needed to workaround the default include paths problem (this is still TODO).

4 Using the same path for both sysroot and build-sysroot

4.1 The new context

In §2.2, we've seen that the build process expect a mingw/include directory in build-sysroot, while it does not expect it in sysroot. Further more in §2.3, we've seen that sysroot/include and sysroot/mingw/include were not searched for includes and in §3.1 and §3.2, that the build-sysroot does not exist in default search paths. As this seem a bit weird that sysroot was not working the same way as build-sysroot, another test was runned, using the same path for both --with-sysroot and --with-build-sysroot and run all the same tests as for from §2 to §3. Note: to not be too much borring, only the differences will be given.

The context can be sumarized like this : test3 does not exist any more and --with-build-sysroot has the same value as --with-sysroot.

  • The build process now expect mingw/include in test1.
  • test1/mingw/include is now searched (sysroot/mingw/include)

Do not not forget that test3 does not exist anymore in this context.

4.2 Includes required at build time are now searched in:

  • Searched in /<install-dir>/<arch>/include
  • Searched in /<install-dir>/<arch>/test1/mingw/include (sysroot/mingw/include)
  • Not searched in any other locations beneath <intall-dir>

4.3 Default paths for the resulting MinGW GCC

Installation, programs and libraries paths, are the same as in §3.1. Includes paths differs from the ones in §3.1

In §3.1, include paths were:

  1. <reloc-dir>/<arch>/test1<install-dir>/include
  2. <install-dir>/lib/gcc/<arch>/<version>/include
  3. <install-dir>/<arch>/include
  4. <reloc-dir>/<arch>/test1/mingw/include
  5. <reloc-dir>/lib/gcc/<arch>/<version>/include

Now the include search paths list is:

  1. <reloc-dir>/<arch>/test1<install-dir>/include
  2. <install-dir>/lib/gcc/<arch>/<version>/include
  3. <install-dir>/<arch>/include
  4. <reloc-dir>/lib/gcc/<arch>/<version>/include
  5. <reloc-dir>/<arch>/test1/mingw/include

4.4 Comments on the latter

The item initial item #4 is now at position #5 and the initial item #5 is now at position #4. The only difference is the permutation of <reloc-dir>/<arch>/test1/mingw/include and <reloc-dir>/lib/gcc/<arch>/<version>/include which are still the last in the search list.

4.5 Default paths for a relocatable MinGW GCC

Paths are the same as in §3.3, excepting that two include paths are swaped, what is a very important thing.

4.6 Default paths for a single versioned relocatable MinGW GCC

All paths are exactly the same as in §3.5 (there was only one include path, so we can forgot about the permutation).

The comment about the include path is the same as in §3.6, that is to say “ There are no good candidates for includes ”.

5 Without a build sysroot option

The latter tests in §4 were made using the same path for sysroot and build sysroot. It was interresting to test weither or not the result would be the same whith no build sysroot, providing in this case, build sysroot is supposed to be defaulted to the value of sysroot. So we may expect the result to be the same, but it is not exactly : the two last include search paths are swaped again, thus the order is back to the same as in §3.1.

Although this seems funny at first sight, using a build sysroot with the same value as sysroot or using no build sysroot at all, has an impact on the default include search paths ordering.

All the remaining stuff is the same as the whole of §4.


  • TODO: a workaround for the default include paths (probably using the specs file)
  • TODO: run the same test and the same analysies with some others
    • --with-sysroot=...
    • --with-local-prefix=...
    • --with-build-sysroot=...
  • TODO: run the same tesst and the analysies without a setting for --with-build-sysroot.


This wiki is not a forum for discussion of usage issues. Please use the list instead. We do not allow creation of comments by anonymous or untrusted users, on any page.
Site Status

Site maintenance performed successfully, site online Dec 13th 12:00 AM Eastern.