Compacting Binary Files and Testing

1. Compacting binary files

.EXE files of cross-compilers contain debugging symbols which are useless for our purpose. It's recommended to strip them so EXE files will be smaller and will load faster.

Open MinGW shell and run the following commands:

$ cd /opt/crosstool/gcc-4.9.2-glibc-2.19
$ strip `find . -name '*.exe' -or -name '*.dll'`

2. Resolving dependencies

Run the following command to figure out cumulative list of dependency DLLs:

$ cd /opt/crosstool/gcc-4.9.2-glibc-2.19
$ strings `find . -name '*.exe' -or -name '*.dll'` | \
  sort -u | grep -F -i '.dll'

Next command will give fine-grained output:

$ find . -name '*.exe' -or -name '*.dll' | awk \
  '{print("echo "$0" ; (strings "$0" | sort -u | fgrep -i .dll)")}' | \

Please copy appropriate MinGW DLLs to related directories carefully.

Final result should look like this:


3. Testing of the cross-compiler

  • 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 BASE=C:\MinGW\msys\1.0\opt\crosstool\gcc-4.9.2-glibc-2.19
    set CROSSPI_HARDFP=%BASE%\arm-linux-gnueabihf\bin\arm-linux-gnueabihf
    set CROSSPI_SOFTFP=%BASE%\arm-linux-gnueabi\bin\arm-linux-gnueabi
    %CROSSPI_HARDFP%-gcc hello1.c -o hello1-hardfp
    %CROSSPI_HARDFP%-gcc -static hello1.c -o hello1-hardfp-static
    %CROSSPI_HARDFP%-g++ -std=c++11 hello2.cpp -o hello2-hardfp
    %CROSSPI_HARDFP%-g++ -std=c++11 -static hello2.cpp -o hello2-hardfp-static
    %CROSSPI_SOFTFP%-gcc hello1.c -o hello1-softfp
    %CROSSPI_SOFTFP%-gcc -static hello1.c -o hello1-softfp-static
    %CROSSPI_SOFTFP%-g++ -std=c++11 hello2.cpp -o hello2-softfp
    %CROSSPI_SOFTFP%-g++ -std=c++11 -static hello2.cpp -o hello2-softfp-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 Raspberry Pi device to make sure they work as expected.

4. Voila

You may want to add "make" tool from MinGW to your cross-compiler, because there's no default "make" tool in Win32 environment. MinGW "make" is located in C:\MinGW\bin.

Borrowing "rm" tool somewhere also makes sense, because there's no rm.exe in bare Windows and Eclipse 'Clean Project' feature depends on rm.exe. MinGW "rm" tool didn't work in Windows 8 for some reason, so I took rm.exe from UnxUtils project.

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.

5. Maintenance

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

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