[Turn] what is cross compiler, why use a cross-compiler?

First, what is cross compiler

Compiler running in a computer environment, compile the code to run in another environment, we call this compiler supports cross-compilation. This compilation process is called cross-compilation.

Simply put, it is to generate executable code on another platform on a platform.

It should be noted that the so-called platform, actually consists of two concepts: the architecture (Architecture), OS (OperatingSystem). The same architecture can run different operating systems; likewise, can run the same operating system on a different architecture. For example, we often say that x86 Linux platform is actually the Intel x86 architecture and Linux for x86 operating system collectively; and x86 WinNT platform is actually the Intel x86 architecture and Windows NT for x86 operating system for short.

The emergence of cross-compiling and pop concept is extensive and development of embedded systems (Embedded Systems) synchronization.

We used computer software, needs to compile way, the use of high-level computer language code (such as C code) compiler (compile) into the computer recognizes and binary code execution. For example, we on the Windows platform, use the Visual C ++ development environment, programming and compiled into an executable program. In this way, we use the Windows tools developed on the PC platform executable (compiled in the current platform, the program can only be compiled into the current platform to run.) For Windows itself, this process is called native compilation compilation, Chinese understandable compiled based machine. However, during the development of embedded systems, the target platform running programs typically have limited storage space and computing power, such as the common platform for ARM, which is generally static storage space is about 16 to 32MB, while the CPU clock speed probably between 100MHz to 500MHz. In this case, the native compiler on ARM platforms are less likely, this is because the general compiler tool chain (compilation tool chain) requires a lot of storage space, and requires a strong CPU power. To solve this problem, cross-compilation tools came into being. By the cross compiler tool, we can in a very strong CPU power, storage space, enough to host platform (such as a PC) compile executable programs for other platforms.

To cross compiler, we need to be installed on the host platform corresponding cross compiler chain (crosscompilation tool chain), and then use this cross compiler to compile tool chain our source, ultimately generated code can be run on the target platform. Common examples of cross-compiled as follows:

1 on Windows PC, using the ADS (ARM development environment), using armcc compiler, executable code can be compiled for the ARM CPU.

2, on the Linux PC, use arm-linux-gcc compiler, executable code can be compiled for Linux ARM platform.

3, on the Windows PC, use cygwin environment running arm-elf-gcc compiler, executable code can be compiled for the ARM CPU.

Second, why use a cross-compiler

Sometimes because the destination is not allowed or can not install the platform we need a compiler, and we need some of the features of the compiler;

Sometimes because of lack of resources on the destination platform, the compiler can not run what we need;

Sometimes it is because the destination platform has not been established, even the operating system are not, not to mention what the compiler is running.

Third, local compile and compare cross compiler

Native compilation: native compilation can be understood as, in the current platform compilation, compiled by the program can only be run into the current platform. Usually we have a common software development, it is of native compilation. For example, we are on the x86 platform, programming and compiled into an executable program. In this way, we use tools to develop for the platform on x86 x86 platform itself executable program, the compilation process called local compilation.

Cross-compiling: cross compiler can be understood as, in the current platform compilation, compiled by the program can be run in a different system architecture to another target platform (the platform that they can not do, so let other platforms to dry) on, but the compiler platform itself can not run the program. For example, we are on the x86 platform, programming and compiled into the program can run on the ARM platform, resulting compiled program on the x86 platform is not running, it must be placed on the ARM platform to run.

Guess you like

Origin www.cnblogs.com/MakeView660/p/11275057.html