Create a cross-compiling environment for arm-linux

Source: Internet
Author: User
Article Title: create a cross-compiling environment for arm-linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Cross-compilation environment

Cross-compilation is an important technology in the embedded development process. Its main feature is that the program code executed on a machine is not compiled and generated on the local machine, but compiled and generated by another machine, generally, the former is called the target machine, and the latter is called the host. The main reason for cross-compilation is that most embedded target systems cannot provide sufficient resources for the compilation process, so they have to transfer the compilation project to a high-performance host.

The cross-compiling environment in linux includes the following parts:

Gcc for the target system

Binutils, a binary tool for the target system

Standard c library glibc of the target system

Linux kernel header file of the target system

Steps for creating a cross-compilation environment

Download source code

Download the source code including binutils, gcc, glibc, and Linux kernel (note that the glibc and kernel source code versions must be consistent with the actual version used on the target machine ), set the shell variable PREFIX to specify the installation path of the executable program.

Compile binutils

Run the configure file, use the -- prefix = $ PREFIX parameter to specify the installation path, use the -- target = arm-linux parameter to specify the target machine type, and then run make install.

Configure the Linux kernel header file

First, execute make mrproper to clean up, and then execute make config ARCH = arm (or make menuconfig/xconfig ARCH = arm) for configuration (note, you must use ARCH = arm to specify the cpu architecture in the command line, because the default architecture is the cpu architecture of the host). This step requires detailed configuration based on the actual situation of the target machine, in the experiment, the target machine is HP's ipaq-hp3630 PDA, so the system type is set to SA11X0, SA11X0 Implementations select Compaq iPAQ H3600/H3700.

After the configuration is complete, copy the kernel header file to the installation directory: cp-dR include/asm-arm $ PREFIX/arm-linux/include/asm cp-dR include/linux $ PREFIX/arm-linux/include/linux

First gcc Compilation

Run the configure file, use the -- prefix = $ PREFIX parameter to specify the installation path, and use the -- target = arm-linux parameter to specify the target machine type, run the -- disable-threads, -- disable-shared, and -- enable-versions = c parameters, and then run make install. This step will generate the simplest gcc. Since compiling the entire gcc requires the glibc library of the target machine, it does not exist yet. Therefore, you must first generate the simplest gcc, it only needs to be able to compile the glibc library of the target machine.

Cross-compile glibc

The code generated in this step is for the cpu of the target machine, so it is a cross-compilation process. The linux kernel header file is used in this process. The default path is $ PREFIX/arm-linux/sys-linux. Therefore, you need to create a soft connection named sys-linux in $ PREFIX/arm-linux, make the include directory where the kernel header file is located. Alternatively, you can use the -- with-headers parameter in the configure command to specify the actual path of the Linux kernel header file.

The running parameters of configure are set as follows (because it is cross-compilation, you need to set the compiler variable CC to arm-linux-gcc ):

CC = arm-linux-gcc./configure -- prefix = $ PREFIX/arm-linux -- host = arm-linux -- enable-add-ons

Finally, execute configure and make install according to the above configuration. Even if the cross-compilation process of glibc is completed, it should be noted that, the installation path of glibc is set to $ PREFIXARCH = arm/arm-linux. If this is not set properly, the header file and library of glibc may not be found during the second gcc compilation.

Second gcc Compilation

Run configure and set the parameter to -- prefix = $ PREFIX -- target = arm-linux -- enable-languages ages = c, c ++.

Run make install.

So far, the entire cross-compilation environment is completely generated.

Notes

First, stdio may not be found when gcc is compiled for the first time. h error. The solution is to modify the gcc/config/arm/t-linux File and add-Dinhibit_libc and-D _ gthr_posix_h to the setting of the TARGET_LIBGCC2_CFLAGS variable.

Second, for glibc library with 2.3.2 version, compilation of linuxthread/sysdeps/pthread/sigaction. c may encounter errors that need to be addressed through the patch glibc-2.3.2-arm.patch: Run patch-p1 <glibc-2.3.2-arm.patch

The Third and Second gcc compilation may encounter libc. so errors, which need to be manually modified by using the text editor.

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.