Download Summary

Transcript
Cross-platform Compilation
Traditional compilers transform the source code into native executables. In this
context, native means that it runs on the same platform of the compiler, and a
platform is a combination of hardware, operating system, application binary
interface (ABI), and system interface choices. These choices define a mechanism that
the user-level program can use to communicate with the underlying system. Hence,
if you use a compiler in your GNU/Linux x86 machine, it will generate executables
that link with your system libraries and are tailored to run on this exact same
platform.
Cross-platform compilation is the process of using a compiler to generate executables
for different, non-native platforms. If you need to generate code that links with
libraries different to the libraries of your own system, you can usually solve this by
using specific compilation flags. However, if the target platform where you intend
to deploy your executable is incompatible with your platform, such as when using
a different processor architecture, operating system, ABI, or object file, you need to
resort to cross compilation.
Cross-compilers are essential when developing applications for systems with
limited resources; embedded systems, for instance, are typically composed of lower
performance processors with constrained memory, and since the compilation process
is CPU and memory intensive, running a compiler in such systems, if possible, is
slow and delays the application development cycle. Therefore, cross-compilers are
invaluable tools in such scenarios. In this chapter, we will cover the following topics:
• A comparison between the Clang and the GCC cross-compilation approaches
• What are toolchains?
• How to cross-compile with Clang command lines
• How to cross-compile by generating a custom Clang
• Popular simulators and hardware platforms to test target binaries