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.4.1-glibc-2.10.1 $ strip `find . -name '*.exe'`
2. Resolving dependencies
Some .EXE files of cross compiler depend on MinGW DLLs. Let's fix that:
$ cd /opt/crosstool/gcc-4.4.1-glibc-2.10.1 $ cp /mingw/bin/libiconv-2.dll \ i486-linux-gnu/libexec/gcc/i486-linux-gnu/4.4.1/ $ cp /mingw/bin/libiconv-2.dll \ x86_64-linux-gnu/libexec/gcc/x86_64-linux-gnu/4.4.1/
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 BASE1=C:\MinGW\msys\1.0\opt\crosstool set BASE2=%BASE1%\gcc-4.4.1-glibc-2.10.1 set CROSS32=%BASE2%\i486-linux-gnu\bin\i486-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.
4. 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 -zcvf my-cross-compiler.tar.gz gcc-4.4.1-glibc-2.10.1
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 Linux workstation (/usr/include, /usr/lib, /lib) to your cross-compiler directory.
>> Read next section or
buy already prepared
cross-compiler (€10) to save your time.