TLDR

    Download links and install instructions
are at the end of this article.


Preface & Content

You want to have a GCC toolchain to compile C/C++ programs for Linux, while you work on your Windows machine? You already use Cygwin on Windows and have Windows 7 / 8 or Windows 10 and do not want to use a slow Virtual Machine?

  • Then you could either switch to use Windows Subsystem for Linux on Windows 10, which provides a more modern alternative provided by Microsoft. Just search for "Ubuntu" or the name of your favourite Linux distribution in the Microsoft Store and click on install.
  • Or you can follow this tutorial to build a GCC Cross-Compiler in Cygwin if you don't want to or can't switch to WSL.

This will be a complete walktrough of the process to create a cross-compile toolchain for cygwin with linux 32 bit (i686) or 64 bit (x86_64) as target.

The speed of this process depends on your internet connection and your hardware. The complete procedure takes about 3 hours on an Intel I7-4720H 2.60GHz CPU with 16GB 1600 MHz DDR3 RAM and a Samsung 850 EVO mSata SSD.



Cygwin tool installation

Download the cygwin installer setup-x86_64.exe from cygwin.com. The crosstool-ng build will need some utilities to succeed. Install the following packages via the graphical installer or use the command line below.

  • tar
  • wget
  • gcc-core
  • gcc-g++
  • binutils
  • make
  • cmake
  • automake
  • autoconf
  • git
  • patch
  • unzip
  • flex
  • bison
  • gperf
  • help2man
  • libtool
  • gettext
  • libgmp10
  • libgmp-devel
  • libmpfr6
  • libmpfr-devel
  • libmpc3
  • libmpc-devel 
  • libncurses-devel
  • libintl-devel
setup-x86_64.exe -a x86_64 -d -q -P "tar,wget,gcc-core,gcc-g++,binutils,make,cmake,automake,autoconf,git,patch,unzip,flex,bison,gperf,help2man,libtool,gettext,libgmp10,libgmp-devel,libmpfr6,libmpfr-devel,libmpc3,libmpc-devel,libncurses-devel,libintl-devel"

Building crosstool-ng

Open a bash prompt - named 'Cygwin64 Terminal' in the start menu - and execute the following steps. This should build and install crosstools-ng from source and allows the build of recent gcc versions. A benefit of using crosstool-ng is the support for parallel compilation of the target toolchain. This results in an optimal CPU usage of 100% during compilation.


Allowing a case-sensitive file system

Execute the follwing script with a bash prompt (Cygwin64 Terminal) as Administrator (Right-click the shortcut in the start menu. Then select "Run as Administrator"). This configures the Windows file system to allow case-sensitive filenames. You can read more here.

Reboot your PC after this step!
reg ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Kernel" /v obcaseinsensitive /t REG_DWORD /d 0 /f

Bug

    Activating the case-sensitivity may break WSL!

Building the toolchain

Start the configuration with the following code snipped. This will create a new directory named compile-cs on your C-drive and mount this folder as case-sensitive file system under /usr/compile. You will need administrator rights on your PC to create a folder directly on your root of the hard drive. So adjust the source path as desired.


The next step is to configure the created toolchain.

Select the following under Path and misc options:

  • Local Tarballs: /usr/compile/src
  • Work Directory: /usr/compile/.build
  • Prefix Directory: /usr/compile/x-tools/${CT_TARGET}

Select under Operating System:

  • Target OS: linux

Activate C++ Support under C compiler:

  • C++

Select the Target options as desired:

i686-unknown-linux-gnu

  • Architecture: x86
  • Architecture Bitness: 32
  • Architecture Level: i686

x86_64-unknown-linux-gnu

  • Architecture: x86
  • Architecture Bitness: 64

powerpc64-unknown-linux-gnu

  • Architecture: powerpc
  • Architecture Bitness: 64

Build additional libraries under C Compiler (optional):
  • Compile libssp: Yes
  • Compile libsanitizer: yes

Save the configuration and start the build with the following command:

ct-ng build
This will take some time.
So be prepared to do something else meanwhile.

Creating a tarball

Execute the following script via bash prompt (Cygwin64 Terminal) to create a final archive. This will contain the complete toolchain including system libraries (libc, libcxx) and linux headers.


Installing the toolchain

Add the folder /usr/local/${TOOLCHAIN_NAME}/bin to your path environment variable (Replace ${TOOLCHAIN_NAME} with the toolchain-name).

Testing the toolchain

Download the gcc-test.zip archive and run make main_i686 or make main_x86_64. This will build both test applications below via make (c and c++ version) and analyze the generated files. 

The respective .txt file contains the generated signature and import table of each application. The content should be similar to the displayed below. You will need a linux machine to run the generated binary files. This can be accomplished with a virtual machine.


Files


TLDR

    Download i686-unknown-linux-gnu.tar.gz
or x86_64-unknown-linux-gnu.tar.gz
and execute the steps in
Installation of the toolchain


gcc 10.2.0 for cygwin64 3.1.7

gcc 9.2.0 for cygwin64 3.0.7

gcc 7.2.0 for cygwin64 2.9.0

(Un-)License

See https://www.gnu.org/ and https://github.com/crosstool-ng/crosstool-ng for the applying licenses regarding the used software.


Regarding the used scripts / code on this page:

This is free and unencumbered software released into the public domain.


Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.


In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


For more information, please refer to http://unlicense.org/