Cross-compiler Arm-Linux-gcc

Source: Internet
Author: User

(1) Introduction to cross-Compiler


A compilation program running in a computer environment can compile the code running in another environment. This compilation process is called cross-compilation. to put it simply, it is to generate executable code on another platform.
(2) architecture and Operating System

(1) common architectures include arm and x86 architectures.

(2) common operating systems include Linux and Windows.

(3) the same architecture can run different operating systems, such as x86 Linux and Windows, and arm can run Linux and wince.

(4) The same operating system can run on different architectures. For example, Linux can run on x86 or arm.

(5) the same program cannot run on multiple platforms. For example, Windows applications cannot run on Linux. to run an application on another platform, you must use a compiler for the platform to re-compile the binary code of the application. for example, to run QQ Software on windows in Linux, follow these steps:
1. QQ program source code
2. Use the Linux compiler to compile the source code of the QQ Software.
In this way, the compiled executable program can be run in Linux. Therefore, how to enable arm to run your application requires a compiler for arm to compile the program.

(3) reasons for using the Cross Compiler

The operating system can be run on arm, so you can use arm as a computer. Theoretically, you can use a local compiler on arm to compile the program. however, the compiler will generate a large number of intermediate files during program compilation, which will occupy a lot of memory and disk space and require high CPU processing speed, for example, the memory and disk space of s3c2440a are only dozens to 100 MB, and the CPU is only 400-500 MHz, which does not meet the compilation program requirements. therefore, during the embedded development of arm-Linux, programs that can run on the arm must be compiled on the PC (x86 structure) and then downloaded to the arm for running. this uses the cross compiler.

To perform cross-compilation, you need to install the corresponding cross-compilation tool chain on the host platform, and then use this cross-compilation tool chain to compile your source code, finally, code that can be run on the target platform is generated. the tool chain for cross-compilation can be downloaded from the Internet or created by yourself. however, the compiler is not omnipotent. Due to version restrictions, an error will be reported when compiling some programs. common cross-compilation tool chains include:

(1) Cross-2.95.3 tar: This version is earlier and is not used except for compiling Vivi.

(2) arm920t-eabi.tgz: 4.1.2 version of the compiler, Eabi support, can compile tx2440a Development Board on all programs.

(3) arm-Linux-GCC: 4.3.2 compiler, which supports Eabi, is the most common cross tool chain.

Attention !!!

What is Eabi?
Eabi, embeded application binary interface, that is, embedded application binary interface, is a specification that describes the connection to the target code, the library target code, the executable file image, how to connect, execute and debug, and the generation process of the target code, and the C and C ++ language interfaces, it is the basic specification for compiling connection tools and the basis for studying their working principles. in short, Eabi is a compilation specification. during compilation, the cross compiler will use hard floating-point operations for floating-point operations, and for processors without hard floating-point operations, such as S3C2440, it will use soft floating point, but this will be greatly limited in speed, while Eabi optimizes floating point operations, improving the performance of floating point operations and saving Compilation Time.


(4) install the cross tool chain arm-Linux-GCC 4.3.2

Installing the cross-compiler Arm-Linux-GCC is to install the corresponding cross-compilation tool chain on the host platform (PC Linux operating system). In other words, is to install the cross-compiler Arm-Linux-GCC 4.3.2 in the Linux operating system. installation steps:

(1) Start the Samba server, open the shared directory/home/lishuai, copy the compressed file arm-linux-gcc-4.3.2.tgz to/home/lishuai.

(2) decompress the software package arm-linux-gcc-4.3.2.tgz.

[Root @ localhost lishuai] # tar xzvf arm-linux-gcc4.3.2.tgz

1. directory 4.3.2 is the directory of the cross compiler. from the arm-linux-gcc-4.3.2.tgz decompression information, the software package needs to be decompressed under usr/local/arm, but actually decompressed to the shared directory/home/lishuai

2. enter the directory usr/local/, and the arm folder is not found. Therefore, create an arm folder and move directory 4.3.2 To the new directory usr/local/arm. 4.3.2/bin is the executable file of arm-Linux-GCC.
[Root @ localhost local] # mv/home/lishuai/usr/local/ARM/4.3.2 ./

3. go to the/usr/local/ARM/4.3.2/bin directory, and you can see different types of compilers. however, it is often used in arm-Linux-GCC. in fact, it is also a GCC compiler, which is consistent with the GCC usage method, but this compiler is for the ARM architecture, Linux operating system compiler. the compiler can be used to compile the applications running on the Linux operating system on the arm.

4. go to the/usr/local/ARM/4.3.2/ARM-None-Linux-gnueabi directory. the lib directory stores the library files, and the applications you write depend on these library files during runtime.

5. The Source Code cannot be compiled at this time. The system will usually prompt that the command arm-Linux-GCC cannot be found. This is an environment variable. Therefore, you must modify the environment variable path.
[Root @ localhost lishuai] # vi/etc/profile

Add environment variables under the line "Export path user LOGNAME mail hostname histsize inputrc,
Input: Export Path =/usr/local/ARM/4.3.2/bin: $ path
Specify the path of the variable as the path of the cross compiler to tell the operating system to find the executable file in the directory/usr/local/ARM/4.3.2/bin.
6. [root @ localhost lishuai #: Source/etc/profile

// Make the modified configuration file/etc/profile take effect

7. Check the version of the arm-Linux-GCC compiler.

[Root @ localhost lishuai] # arm-Linux-gcc-V

(5) arm-linu-GCC application instance

Example: Use the boa-0.94.13.tar.tar
1. Start the SMB server and place the source code package in the Shared Folder/home/lishuai.
2. Enter the command: Tar xzvf boa-0.94.13.tar.tar

// Decompress the source code package

// If a MAKEFILE file is included in the general source code package, you can compile it by executing make. However, the makefile is not included in the source code package. In this case, executing make is invalid.

// No makefile is available, but the configure file is found. You can run the configure file to generate the makefile.
[Root @ localhost lishuai] #./configure

// Run the configure file to generate the MAKEFILE file
// To compile a program on the ARM platform, you need to use a cross compiler. the green uppercase letters in the MAKEFILE file are all makefile variables. You can see the variable cflags =-g-O2-pipe-wall-L. This variable is used to set the compilation options. The variable CC = GCC, this variable is used to set the compiler to be used. to use the cross-compiler Arm-Linux-GCC, set this variable to CC.
= Arm-Linux-GCC, CPP = arm-Linux-gcc-E, save and exit.
[Root @ localhost lishuai] # Make

// Execute make to compile
// Generate an executable program named BOA, which can be downloaded to arm for execution.

In fact, this process is also called transplantation. porting is to modify, configure, and cross-compile a source code package, and then download it to a platform for running. for example, bootloader, kernel, and QT are often transplanted.


A compilation program running in a computer environment can compile the code running in another environment. This compilation process is called cross-compilation. to put it simply, it is to generate executable code on another platform.
(2) architecture and Operating System

(1) common architectures include arm and x86 architectures.

(2) common operating systems include Linux and Windows.

(3) the same architecture can run different operating systems, such as x86 Linux and Windows, and arm can run Linux and wince.

(4) The same operating system can run on different architectures. For example, Linux can run on x86 or arm.

(5) the same program cannot run on multiple platforms. For example, Windows applications cannot run on Linux. to run an application on another platform, you must use a compiler for the platform to re-compile the binary code of the application. for example, to run QQ Software on windows in Linux, follow these steps:
1. QQ program source code
2. Use the Linux compiler to compile the source code of the QQ Software.
In this way, the compiled executable program can be run in Linux. Therefore, how to enable arm to run your application requires a compiler for arm to compile the program.

(3) reasons for using the Cross Compiler

The operating system can be run on arm, so you can use arm as a computer. Theoretically, you can use a local compiler on arm to compile the program. however, the compiler will generate a large number of intermediate files during program compilation, which will occupy a lot of memory and disk space and require high CPU processing speed, for example, the memory and disk space of s3c2440a are only dozens to 100 MB, and the CPU is only 400-500 MHz, which does not meet the compilation program requirements. therefore, during the embedded development of arm-Linux, programs that can run on the arm must be compiled on the PC (x86 structure) and then downloaded to the arm for running. this uses the cross compiler.

To perform cross-compilation, you need to install the corresponding cross-compilation tool chain on the host platform, and then use this cross-compilation tool chain to compile your source code, finally, code that can be run on the target platform is generated. the tool chain for cross-compilation can be downloaded from the Internet or created by yourself. however, the compiler is not omnipotent. Due to version restrictions, an error will be reported when compiling some programs. common cross-compilation tool chains include:

(1) Cross-2.95.3 tar: This version is earlier and is not used except for compiling Vivi.

(2) arm920t-eabi.tgz: 4.1.2 version of the compiler, Eabi support, can compile tx2440a Development Board on all programs.

(3) arm-Linux-GCC: 4.3.2 compiler, which supports Eabi, is the most common cross tool chain.

Attention !!!

What is Eabi?
Eabi, embeded application binary interface, that is, embedded application binary interface, is a specification that describes the connection to the target code, the library target code, the executable file image, how to connect, execute and debug, and the generation process of the target code, and the C and C ++ language interfaces, it is the basic specification for compiling connection tools and the basis for studying their working principles. in short, Eabi is a compilation specification. during compilation, the cross compiler will use hard floating-point operations for floating-point operations, and for processors without hard floating-point operations, such as S3C2440, it will use soft floating point, but this will be greatly limited in speed, while Eabi optimizes floating point operations, improving the performance of floating point operations and saving Compilation Time.


(4) install the cross tool chain arm-Linux-GCC 4.3.2

Installing the cross-compiler Arm-Linux-GCC is to install the corresponding cross-compilation tool chain on the host platform (PC Linux operating system). In other words, is to install the cross-compiler Arm-Linux-GCC 4.3.2 in the Linux operating system. installation steps:

(1) Start the Samba server, open the shared directory/home/lishuai, copy the compressed file arm-linux-gcc-4.3.2.tgz to/home/lishuai.

(2) decompress the software package arm-linux-gcc-4.3.2.tgz.

[Root @ localhost lishuai] # tar xzvf arm-linux-gcc4.3.2.tgz

1. directory 4.3.2 is the directory of the cross compiler. from the arm-linux-gcc-4.3.2.tgz decompression information, the software package needs to be decompressed under usr/local/arm, but actually decompressed to the shared directory/home/lishuai

2. enter the directory usr/local/, and the arm folder is not found. Therefore, create an arm folder and move directory 4.3.2 To the new directory usr/local/arm. 4.3.2/bin is the executable file of arm-Linux-GCC.
[Root @ localhost local] # mv/home/lishuai/usr/local/ARM/4.3.2 ./

3. go to the/usr/local/ARM/4.3.2/bin directory, and you can see different types of compilers. however, it is often used in arm-Linux-GCC. in fact, it is also a GCC compiler, which is consistent with the GCC usage method, but this compiler is for the ARM architecture, Linux operating system compiler. the compiler can be used to compile the applications running on the Linux operating system on the arm.

4. go to the/usr/local/ARM/4.3.2/ARM-None-Linux-gnueabi directory. the lib directory stores the library files, and the applications you write depend on these library files during runtime.

5. The Source Code cannot be compiled at this time. The system will usually prompt that the command arm-Linux-GCC cannot be found. This is an environment variable. Therefore, you must modify the environment variable path.
[Root @ localhost lishuai] # vi/etc/profile

Add environment variables under the line "Export path user LOGNAME mail hostname histsize inputrc,
Input: Export Path =/usr/local/ARM/4.3.2/bin: $ path
Specify the path of the variable as the path of the cross compiler to tell the operating system to find the executable file in the directory/usr/local/ARM/4.3.2/bin.
6. [root @ localhost lishuai #: Source/etc/profile

// Make the modified configuration file/etc/profile take effect

7. Check the version of the arm-Linux-GCC compiler.

[Root @ localhost lishuai] # arm-Linux-gcc-V

(5) arm-linu-GCC application instance

Example: Use the boa-0.94.13.tar.tar
1. Start the SMB server and place the source code package in the Shared Folder/home/lishuai.
2. Enter the command: Tar xzvf boa-0.94.13.tar.tar

// Decompress the source code package

// If a MAKEFILE file is included in the general source code package, you can compile it by executing make. However, the makefile is not included in the source code package. In this case, executing make is invalid.

// No makefile is available, but the configure file is found. You can run the configure file to generate the makefile.
[Root @ localhost lishuai] #./configure

// Run the configure file to generate the MAKEFILE file
// To compile a program on the ARM platform, you need to use a cross compiler. the green uppercase letters in the MAKEFILE file are all makefile variables. You can see the variable cflags =-g-O2-pipe-wall-L. This variable is used to set the compilation options. The variable CC = GCC, this variable is used to set the compiler to be used. to use the cross-compiler Arm-Linux-GCC, set this variable to CC.
= Arm-Linux-GCC, CPP = arm-Linux-gcc-E, save and exit.
[Root @ localhost lishuai] # Make

// Execute make to compile
// Generate an executable program named BOA, which can be downloaded to arm for execution.

In fact, this process is also called transplantation. porting is to modify, configure, and cross-compile a source code package, and then download it to a platform for running. for example, bootloader, kernel, and QT are often transplanted.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.