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.6.3-eglibc-2.13
$ strip `find . -name '*.exe'`

Also cyglto_plugin-0.dll in libexec directories can be deleted. It's a relict of Cygwin build environment, now obsoleted with MinGW liblto_plugin-0.dll in the same directory.


2. Resolving dependencies

Some .EXE files of cross compiler depend on MinGW DLLs. Let's fix that:

$ cd /opt/crosstool/gcc-4.6.3-eglibc-2.13
$ cp /mingw/bin/libiconv-2.dll \
    arm-linux-gnueabihf/libexec/gcc/arm-linux-gnueabihf/4.6.3/
$ cp /mingw/bin/libiconv-2.dll \
    arm-linux-gnueabi/libexec/gcc/arm-linux-gnueabi/4.6.3/

There are other dependencies (libgcc_s_dw2-1.dll, libgcj-11.dll and mingw10.dll) but they seem to be required only for multithread applications and Garbade-Collected Java, so we can leave them behind.


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()
    {
        std::cout << "Hello, c++!\n";
        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.6.3-eglibc-2.13
    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++ hello2.cpp -o hello2-hardfp
    %CROSSPI_HARDFP%-g++ -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++ hello2.cpp -o hello2-softfp
    %CROSSPI_SOFTFP%-g++ -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 -zcvf my-cross-compiler.tar.gz gcc-4.6.3-eglibc-2.13

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 eglibc, 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.