Gentoo Wiki


Please improve it in any way that you see fit, and remove this notice {{Cleanup}} from the article. For tips on cleaning and formatting see Cleanup process

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Please improve it in any way that you see fit, and remove this notice {{Cleanup}} from the article. For tips on cleaning and formatting see Cleanup process

FIXME: update for current toolchains



There really isn't much new in this HOWTO; see the references at the bottom. I just thought I would get it all in one place and relate the extra problems and solutions I ran into. This won't get you the smallest or fastest cross toolchain possible; it's just the basics that worked for me. Also I'm no expert on cross compilers and I've heard they can cause problems with some packages. I haven't had any problems so far but I haven't tested this extensively. If you don't want to compile it all yourself then look here.

Another option, that wasn't available at the time this HOWTO was initially written but would probably be a better option for most people today, is to use colinux.


First you need a working Cygwin installation, with a full set of build tools. I won't go into that here, as there's plenty of information at You will need gcc, make and the rest of the GCC toolchain. I have cygwin-1.3.22 and gcc-3.2-3 installed for the purposes of this HOWTO.

Make sure you choose the "all users" option in the Cygwin installation and either have CYGWIN="ntsec tty" in your system environment variables or set it before starting distccd. HOWTO: Use a Windows box as a distcc server for linux (at Gentoo Forums)

People have asked what the mimimum requirements are for this process, but this has not yet been clarified. It is possible to do this with autoconf, automake, bison, flex, gcc-g++, gettext-devel, make, m4, and openssh; if there are additional requirements, installing these will bring them in automatically.

FIXME: Figure out exact requirements

Once you get Cygwin installed to your liking and can compile with it, you can build the cross-compiler toolchain you will need for compiling programs for Linux.

For this document, the following convention is followed: any command that has cygwin$ at the front is executed in the Cygwin shell on Windows, while any with linux$ in front is one you run on Gentoo or another Linux.

First, environment variables need to be established. I want to keep everything in /usr/local/cross-linux, so this directory is used for the PREFIX environment variable. You may change that, SRC_ROOT and BUILD, but leave the rest as they are stated here:

cygwin$ export PREFIX=/usr/local/cross-linux
cygwin$ export SRC_ROOT=~/
cygwin$ export BUILD=i686-pc-cygwin
cygwin$ export HOST=i686-pc-cygwin
cygwin$ export TARGET=i686-pc-linux-gnu
cygwin$ export BUILDDIR=$SRC_ROOT/build


On Linux, I have binutils- I couldn't get that to compile on Cygwin, so I downgraded to binutils-2.13.1 instead. This version compiled without a hitch. The build steps were as follows. (You may also add --disable-nls to the configure options, but I didn't try it that way.)

cygwin$ cd $SRC_ROOT
cygwin$ tar -xzvf binutils-2.13.1.tar.gz
cygwin$ mkdir -p $BUILDDIR/binutils
cygwin$ cd $BUILDDIR/binutils
cygwin$  ../../binutils-2.13.1/configure --with-included-gettext \
		--target=$TARGET --host=$HOST --build=$BUILD \
		--prefix=$PREFIX -v && \
make && make install

Note: If you have not already done so, add $PREFIX/bin to your PATH before continuing:
cygwin$ export PATH=$PATH:$PREFIX/bin

(This can also be done in the GUI if you have sufficient access on the machine.)

Now test to see if we have binutils working.

cygwin$ $TARGET-ld --version
GNU ld version 2.13.1
Copyright 2002 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.

If you get this message, things are going well.

GLIBC and linux-headers

The general method (should work on any linux distro)

By all accounts, compiling glibc on Cygwin is not worth the effort, so the following steps should be performed under Linux.

The steps below were performed with glibc-2.3.1, but other versions may also work.

linux$ cd /tmp
linux$ mkdir glibc
linux$ cd glibc
linux$ tar -xzvf /usr/portage/distfiles/glibc-2.3.1.tar.gz
linux$ cd glibc-2.3.1
linux$ tar -xzvf /usr/portage/distfiles/glibc-linuxthreads-2.3.1.tar.gz
linux$ mkdir ../build
linux$ cd ../build
linux$ ../glibc-2.3.1/configure --enable-add-ons \
linux$ make
linux$ make install
Note: If make fails when looking for i686-pc-linux-gnu/etc/ this file needs to be created. I simply copied it from the linux system by doing:
linux$ cp /etc/ /usr/local/cross-linux/i686-pc-linux-gnu/etc/

If you get: error: va_start used in function with fixed args, then modify the sscanf function in stdio-common/sscanf.c so that the declaration looks like this (ref BuildCrossToolchainHowto at wiki):

sscanf (const char *s, const char *format, ...)

Now we need to make a slight adjustment and get our kernel headers.

linux$ cd /usr/local/cross-linux/i686-pc-linux-gnu
linux$ ln -s include sys-include            #Do not include this line for GCC 3.2.3
linux$ cd include
linux$ ( cd /usr/include/; tar -cf - linux ) | tar -xf -
linux$ ( cd /usr/include/; tar -cf - asm ) | tar -xf -
Quote: My debian box also needed the asm-generic folder. If this folder exists, it might be a good idea to copy it.


Now you are ready to copy the whole thing to Windows:

cygwin$ cd /
cygwin$ ssh linuxbox '( cd / ; tar -cf - usr/local/cross-linux )' | \
     tar -xf -

Now you should be ready to build gcc.

The Portage assisted method

Note: This method has not been thoroughly tested and may be in need of further refinement.

This method is slightly easier than the general method above. Also this builds you a gentoo-patched version of glibc like what portage installs on your system. It obeys your USE flags and everything. Whether that's a good thing, a bad thing, or totally irrelevant is not clear to the author at this point.

Note: For this example glibc- was used.

You would of course substitute the version you are using where appropriate.

First we need to make a slight modification to the glibc ebuild.

linux$ nano -w /usr/portage/sys-libs/glibc/glibc-

Find the line in the src_compile() function that reads

--prefix=/usr \

and change it to

--prefix=/usr/local/cross-linux/i686-pc-linux-gnu \

then save it.

You will need to rebuild the digest before installing the ebuild.

linux$ ebuild /usr/portage/sys-libs/glibc/glibc- digest

Now we can compile glibc and install it into a temporary directory with one command.

linux$ ebuild /usr/portage/sys-libs/glibc/glibc- install

Now we copy our kernel headers to the temporary directory.

linux$ cd /var/tmp/portage/glibc-
linux$ ( cd /usr/include/; tar -cf - linux ) | tar -xf -
linux$ ( cd /usr/include/; tar -cf - asm ) | tar -xf -
linux$ ( cd /usr/include/; tar -cf - asm-generic ) | tar -xf -

Now we make a tarball that you can install into the root of your cygwin install.

linux$ cd /var/tmp/portage/glibc-
linux$ tar -cjvf /tmp/cross-glibc- usr/local/cross-linux

Now we can get our of the temporary install and clean it up.

linux$ cd
linux$ ebuild /usr/portage/sys-libs/glibc/glibc- clean

Now you can take the tarball you created and untar it into the root of you cygwin install on the windows box.

Note: Be sure to change the ebuild back to the way it was when you're done. You should probably use a portage overlay for this but I leave that as na exercise for the reader.


For this demonstration, gcc-3.2.2 was used because the tarball happened to be available in the distfiles. Again, other versions should also work.

cygwin$ cd $SRC_ROOT
cygwin$ tar -xjvf gcc-3.2.2.tar.bz2

On Cygwin, GCC automatically adds the .exe extension, in following with the Windows file extension convention. Because you are cross-compiling for Linux, you may wish to modify GCC not to do this. To do so, open $SRC_ROOT/gcc-3.2.2/gcc/config/i386/xm-cygwin.h and comment out the EXECUTABLE_SUFFIX macro. This step is not strictly necessary for distcc use, but there isn't any obvious reason why programs compiled for Linux should need this extension.

At this point you are ready to build GCC:

cygwin$ cd $BUILDDIR
cygwin$ mkdir gcc
cygwin$ cd gcc
cygwin$ ../../gcc-3.2.2/configure --enable-languages=c,c++ \
	 --with-included-gettext --enable-shared \
	 --enable-threads=posix \
	 --with-headers=$PREFIX/i686-pc-linux-gnu/include/ \
	 --target=$TARGET --host=$HOST --build=$BUILD \
	 --prefix=$PREFIX -v
cygwin$ make
cygwin$ make install

If it dies during the compile with something like this --

regex.c:5723: undefined reference to `___mempcpy'

-- open $SRC_ROOT/gcc-3.2.2/gcc/fixinc/gnu-regex.c and search for __mempcpy. You should find something like this:

#if defined HAVE_MEMPCPY || defined _LIBC
          *((char *) __mempcpy (errbuf, msg, errbuf_size - 1)) = '\0';
          memcpy (errbuf, msg, errbuf_size - 1);
          errbuf[errbuf_size - 1] = 0;

Change this line --

#if defined HAVE_MEMPCPY || defined _LIBC

-- to --

#if 0 /* defined HAVE_MEMPCPY || defined _LIBC */

-- then empty your build directory and run the configure && make && make install cycle again.

I had to do this but I'm not sure if it is a universal problem with gcc and Cygwin or if it was just a problem with my computer.

If you are in a hurry, you may want to do this step in advance, on the assumption that it will fail for you as well. The error does not come up until well into the compilation process, and starting over that far in can be frustrating.

When that is done, you should have a working cross-compiler. You can test it as follows.

cygwin$ cat > hello.c << EOF
#include <stdio.h>
  printf("hello world\n");
  return 0;

cygwin$ $TARGET-gcc -o hello hello.c

This should produce a "hello" executable that will run cleanly if copied over to a Linux machine.


If everything has worked so far, we can now compile distcc. This should be easy.

Once again, I've used distcc-2.5 because that was the version that happened to be available; once again, other versions should also work.

It is important that all machines that will be participating in the compilation pool have the same version of distcc. If multiple versions are in use at the same time, strange, difficult to debug Heisenbugs can arise.

cygwin$ cd $SRC_ROOT
cygwin$ tar -xjvf distcc-2.5.tar.bz2
cygwin$ cd distcc-2.5
cygwin$ ./configure --prefix=/usr/local
cygwin$ make && make install

That's it. You should now be able to run distccd on Windows and add it to the pool.

cygwin$ export PATH="/usr/local/cross-linux/bin:/usr/local/cross-linux/$target/bin:$PATH"
cygwin$ distccd --daemon --nice 19
Note: For a Windows 98 machine the --no-detach -option must be defined in order to open port 3632!

Note: As of distcc 2.18 the --allow option is required, see the man page for details of how to specify an appropriate value.

Note: Nice value of 19 will run distcc as windows 'Low' priority, you may want to change this to 6 (windows 'Below Normal') if you run background processes such as SETi.

You can now add the Windows machine to the list of available distcc hosts. Verify that things are working by initiating a compilation and checking to see that it distributes properly to all hosts in the pool, including the new Windows node.

Optional: Setting up distccd as a service in windows

You may wish to make distcc permanently available by setting up distccd as a service. On NT derived versions of Windows, "services" are functionally equivalent to Unix daemons. Services are only available on NT based operating systems: NT, 2000, and XP; they are not available on Windows ME, 9x, or 3.1.

There are several ways to set up a new service, but the following steps, using the Cygwin tools, are known to work. This approach depends on Cygwin's cygrunsrv package, which will now need to be installed if it wasn't already available.

We need a script to make sure distccd gets the proper PATH. For these steps, we will put this script at /usr/local/bin/

File: /usr/local/bin/

DISTCCD_ARGS="--nice 19 --no-detach --daemon"


Make the script executable:

cygwin$ chmod +x /usr/local/bin/ 

Now we install the service:

cygwin$ cygrunsrv -I distccd --path /usr/local/bin/ \

See this post for an alternative approach.

Now you can start and stop distccd from the services control panel applet or with cygrunsrv within the Cygwin shell.


This howto was originally posted on the gentoo-forums by PowerFactor(me) and feedback from several others in that thread has since been incorporated into it. Thanks to Veto especially for your feedback and for making binaries available.

Veto's (Rob Snow) binary packages can be found at His binaries are created via this HOWTO and are updated fairly often as Gentoo-Stable changes GCC, Binutils or GLIBC versions. Questions or info about Veto's (Rob's) binary tool-chain can be found at


Appendix A: Making it smaller

If packaged, these steps produce a huge tarball -- several dozen megabytes or more.

The size can be reduced by nearly half if carefully pruned, but be aware that this has not been well tested and may raise errors.

When building glibc on Linux, you can remove a lot of material, including most of the directories inside /usr/local/cross-linux/i686-pc-linux-gnu, with the exception of the include and lib subdirectories. It is possible to further prune the contents of the lib directory by following the steps in Khan's article.

When the Windows box is finished, you can remove the info and man directories from /usr/local/cross-linux.

The smallest I've managed is 27MB, not including distcc, but further reduction is possible: for example, a 22MB tarball is available, so there's at least another 20% that can come out at the end of the process.

Appendix B: Applying Gentoo patches binutils and gcc

If you would like to have a binutils and gcc in your cross toolchain with the same patches as applied to the gentoo versions you can use Portage to apply the patches for you.

We'll use binutils for the example, the procedure is the same for gcc. Be sure to substitute the correct versions where appropriate.

First we have portage download and unpack the appropriate files and apply the patches.

linux$ ebuild /usr/portage/sys-devel/binutils/binutils- unpack

Now we create a tarball from the patched source tree.

linux$ cd /var/tmp/portage/binutils-
linux$ mv binutils- binutils-
linux$ tar -cjvf /tmp/cross-binutils- binutils-

Then we can clean out the portage work directory.

linux$ cd
linux$ ebuild /usr/portage/sys-devel/binutils/binutils- clean

Now you can use the tarball you created in place of the standard source tarball in the build procedure.

You will need to use extra configure options and possibly extra make commands to enable the features provided by some of the patches. Refer to the relevant ebuild for ideas.

Be aware that packages patched in this manner may or may not build on cygwin at any given point in time. At this point the author has not been able to get gcc patched by this method to even configure on cygwin. But binutils builds fine. Your mileage may vary.

Retrieved from ""

Last modified: Fri, 05 Sep 2008 03:54:00 +0000 Hits: 47,035