Testing the Cross-Compiler

1. Testing

  • Create C:\cc_test folder
  • Create the file C:\cc_test\hello1.c with the following contents:
    #include <stdio.h>
    #include <limits.h>
    static long x = LONG_MIN;
    int main()
        printf( "Hello, world!  "
                "LONG_MIN is %ld, INT_MAX is %d\n",
                x, INT_MAX );
        return 0;
  • Create the file C:\cc_test\hello2.cpp with the following contents:
    #include <iostream>
    int main()
        auto  lambda = []( const std::string&  s ) {
            std::cout << "Hello, " << s << "!\n";
        lambda( "c++" );
        return 0;
  • Create the file C:\cc_test\test.cmd with the following contents:
    @echo off
    set BASE1=C:\MinGW\msys\1.0\opt\crosstool
    set BASE2=%BASE1%\gcc-4.9.2-glibc-2.19
    set CROSS32=%BASE2%\i586-linux-gnu\bin\i586-linux-gnu
    set CROSS64=%BASE2%\x86_64-linux-gnu\bin\x86_64-linux-gnu
    %CROSS32%-gcc hello1.c -o hello1-32bit
    %CROSS32%-gcc -static hello1.c -o hello1-32bit-static
    %CROSS32%-g++ hello2.cpp -o hello2-32bit
    %CROSS32%-g++ -static hello2.cpp -o hello2-32bit-static
    %CROSS64%-gcc hello1.c -o hello1-64bit
    %CROSS64%-gcc -static hello1.c -o hello1-64bit-static
    %CROSS64%-g++ hello2.cpp -o hello2-64bit
    %CROSS64%-g++ -static hello2.cpp -o hello2-64bit-static
  • Run the file C:\cc_test\test.cmd and make sure there are no compiler errors.
  • Copy build results to VM shared folders and test them on real Linux to make sure they work as expected.

2. Voila

In order to pack final archive with your new shiny cross-compiler, open MinGW shell and run the following commands:

$ cd /opt/crosstool
$ tar -h -zcf my-cross-compiler.tar.gz gcc-4.9.2-glibc-2.19

Then copy my-cross-compiler.tar.gz from MinGW virtual machine to the host system via shared folder. You may use WinRAR in pure Win32 environment to unpack .tar.gz reliably.

After cross-compiler is tested in host system and confirmed to work, both Cygwin and MinGW virtual machines and all their snapshots can be busted.

3. Maintenance

If you need to use any additional library besides glibc, you should copy relevant files from Linux workstation (/usr/include, /usr/lib, /lib) to your cross-compiler directory.

>> Look at screenshots or buy already prepared cross-compiler (€10) to save your time.