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 CROSSPI_HARDFP=%~dp0\gcc-8.3.0-glibc-2.28\arm-linux-gnueabihf\bin\arm-linux-gnueabihf
    set CROSSPI_SOFTFP=%~dp0\gcc-8.3.0-glibc-2.28\arm-linux-gnueabi\bin\arm-linux-gnueabi
    cd %~dp0
    if exist tmp\. rmdir /S /Q tmp
    mkdir tmp
    
    %CROSSPI_HARDFP%-gcc hello1.c -o tmp\hello1-hardfp
    %CROSSPI_HARDFP%-gcc -static hello1.c -o tmp\hello1-hardfp-static
    %CROSSPI_HARDFP%-g++ -std=c++11 hello2.cpp -o tmp\hello2-hardfp
    %CROSSPI_HARDFP%-g++ -std=c++11 -static hello2.cpp -o tmp\hello2-hardfp-static
    
    %CROSSPI_SOFTFP%-gcc hello1.c -o tmp\hello1-softfp
    %CROSSPI_SOFTFP%-gcc -static hello1.c -o tmp\hello1-softfp-static
    %CROSSPI_SOFTFP%-g++ -std=c++11 hello2.cpp -o tmp\hello2-softfp
    %CROSSPI_SOFTFP%-g++ -std=c++11 -static hello2.cpp -o tmp\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.

2. 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 10 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 --owner=0 --group=0 -h -zcf \
    my-cross-compiler.tar.gz gcc-8.3.0-glibc-2.28

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 Raspberry Pi device (/usr/include, /usr/lib, /lib) to your cross-compiler directory.


>> Read next section or buy already prepared cross-compiler (€10) to save your time.