2.6. Conclusion

Note that there are a lot of subtle differences in the options between the different invocations. For example, building binutils and gcc requires a --target= option whereas glibc requires --build= and --host= options. There are also subtle differences in the --prefix= options, especially with the full build of glibc where you lie and say they're going to be installed in one place but then override a Makefile variable on the command-line at install-time to install the libraries in a different place. This is very important since the shared library mechanism on the target machine will not work properly if you don't do it this way (or at the very least you'll need to place your system-wide shared libraries in a peculiar place on the target machine for your binaries to work).

So what do we have now?

We can demonstrate something is different by cross-compiling a simple "Hello, world!" application.

[cross-test]$ cat hello.c
#include <stdio.h>
int
main (void)
{
        printf ("Hello, world!\n");
        return 0;
}
[cross-test]$ gcc -o hello hello.c
[cross-test]$ file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped
[cross-test]$ ./hello
Hello, world!
[cross-test]$
       

But:

[cross-test]$ export PATH=$PATH:${BASE}/toolchain/powerpc-603e-linux-gnu/bin
[cross-test]$ powerpc-603e-linux-gnu-gcc -o hello hello.c
[cross-test]$ file hello
hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.0.0, dynamically linked (uses shared libs), not stripped
[cross-test]$ ./hello
bash: ./hello: cannot execute binary file